virtual-scroller icon indicating copy to clipboard operation
virtual-scroller copied to clipboard

Scrolling to item

Open SamiKamal opened this issue 11 months ago • 4 comments

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?

SamiKamal avatar Mar 07 '24 09:03 SamiKamal

Hi. If the item hasn’t been rendered yet then its top position is unknown. In those cases, precise scroll-to is impossible.

On Thu, 7 Mar 2024 at 12:10, Sami Ibrahim @.***> wrote:

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:

Obtaining the estimatedItemsHeight. Multiplying it by the itemIndex. However, this method lacks precision because the estimatedItemsHeight can easily deviate. Is there a more accurate approach to determine the scroll position?

— Reply to this email directly, view it on GitHub https://github.com/catamphetamine/virtual-scroller/issues/21, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADUP32XB27SABZVHXAWUU3YXAVIJAVCNFSM6AAAAABEKS55O6VHI2DSMVQWIX3LMV43ASLTON2WKOZSGE3TGMZVGUYTIMA . You are receiving this because you are subscribed to this thread.Message ID: @.***>

catamphetamine avatar Mar 11 '24 09:03 catamphetamine

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?

SamiKamal avatar Mar 12 '24 23:03 SamiKamal

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).

catamphetamine avatar Mar 13 '24 03:03 catamphetamine

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

sachingooo avatar Apr 03 '24 00:04 sachingooo