Search code examples
javascripthtmlcssreactjs

How to stay in same scroll position when adding items to the top of a div?


I want when the user scrolls from the bottom to the top of a div to load more items into that div to the top part of the div and I want to maintain the scroll position (or rather make sure the top item before adding more items is still visible after adding the items)

For example if I have item 100 on the top and 100 more items has been loaded into the div then I want item 100 to still be the focus of the scroll position, currently when I add items to the div it jumps to item 200...

I'd love to get help with this issue, thanks in advance :)


Solution

  • I found this answer useful, I just created the same logic but in React jquery - keep window from changing scroll position while prepending items to a list?