Is there a way to preserve scroll position when prepending items?
I have an infinite list, paginated in both directions. There are no issues when scrolling down and appending items, however when scrolling up the scroll position switches to the first prepended item.
I understand this happens because scrollTop is 0 and stays 0 while the items get prepended. I tried working around it by scrolling to the previously visible item, but it's a very janky experience. Any tips?
What I might want:
- measure prepended items (no dom update)
- add top padding equal to measurement (dom update)
- scroll down equal to added padding (no dom update, other than scrolling)
- actually prepend items, remove padding (dom update)
I understand this happens because scrollTop is 0 and stays 0 while the items get prepended. I tried working around it by scrolling to the previously visible item, but it's a very janky experience. Any tips?
What I might want:
- measure prepended items (no dom update)
- add top padding equal to measurement (dom update)
- scroll down equal to added padding (no dom update, other than scrolling)
- actually prepend items, remove padding (dom update)