Keep list from scrolling up when prepending data in Svelte #733
Unanswered
lucassilvas1
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'm trying to implement "remember position" functionality to a virtual list in Svelte. That means that the user will be placed somewhere in the middle of the list in later sessions/after refreshing the page. Which also means they can scroll both directions.
Now here's the problem, when the user scrolls up, and I try to prepend data to the array, the
scrollOffset
doesn't change, so from the user's perspective, we're effectively "scrolling up" to the top of the list, and they would then have to scroll back down to where they were, before scrolling back up.So I need a way of keeping the
scrollOffset
locked to the item that the user was looking at before I prepended the data. I tried doing this manually, by saving the index of the first element visible in the viewport before the data was prepended and scrolling to that index once the new items have been rendered, but that takes like half a second and is pretty noticeable.TLDR: I need a way to keep the list from jumping back up to the start when prepending data in "bidirectional dynamic infinite scroll mode," if you will.
Does anyone know how to achieve this in Svelte?
Beta Was this translation helpful? Give feedback.
All reactions