Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrolling to item #21

Open
SamiKamal opened this issue Mar 7, 2024 · 4 comments
Open

Scrolling to item #21

SamiKamal opened this issue Mar 7, 2024 · 4 comments

Comments

@SamiKamal
Copy link

SamiKamal commented Mar 7, 2024

Hey, thanks for the amazing work here ❤️

I'm utilizing virtual-scroller to display a vast list of items (10,000+). I'm aiming to scroll the user to a particular item based on its index (e.g., navigating to index 5931). Currently, I determine the scroll position by:

  1. Obtaining thegetAverageItemHeight.
  2. Multiplying it by the itemIndex.
    However, this method lacks precision because thegetAverageItemHeight can easily deviate. Is there a more accurate approach to determine the scroll position?
@catamphetamine
Copy link
Owner

catamphetamine commented Mar 11, 2024 via email

@SamiKamal
Copy link
Author

Umm, wouldn't it be possible if the following happen:

  1. Implement custom smooth scrolling
  2. Add scrollToItem(index) function
  3. When scrollToItem is called scroll to the end by default
  4. As we scroll the items will be rendered
  5. If we came across the item while scrolling then cancel the scroll

Not sure if this is practical though.

Also one random question, would it be possible to fire an event or call a callback when the initial render is done?

@catamphetamine
Copy link
Owner

Umm, wouldn't it be possible if the following happen:

I don't think that it would be practical because the scrolling wouldn't be smooth: it would scroll almost to the end, wait for it to render, then scroll almost to the end, wait for it to render, etc, until item N is rendered.

Also one random question, would it be possible to fire an event or call a callback when the initial render is done?

There's a onItemInitialRender(item) option/property. See the readme (expandable sections).

@sachingooo
Copy link

Love this functionality as well! I agree that it would be fantastic to be able to programmatically scroll to a given element index

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants