virtual-scroller
virtual-scroller copied to clipboard
Scrolling to item
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
getAverageItemHeight
. - 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?
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: @.***>
Umm, wouldn't it be possible if the following happen:
- Implement custom smooth scrolling
- Add
scrollToItem(index)
function - When
scrollToItem
is called scroll to the end by default - As we scroll the items will be rendered
- 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?
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).
Love this functionality as well! I agree that it would be fantastic to be able to programmatically scroll to a given element index