I have an application with a page that has a chat feature. I want this to look and feel like most chat apps, the newest messages are at the bottom of the page, and you scroll up to see more previous messages.
I’ve got the pagination aspect of the infinite scroll working fine. When you scroll to the top of the current page, you get the next set of previous messages.
Unfortunately, when you get to the top of the page, the next page loads in, but the scroll position stays at the top of the page, essentially "skipping" you to the top of the next page of messages. It’s a bad UX.
Atm, I’m adding "markers" for each page. Just div
s with id
s for the page number. When the next set of messages loads in, I scroll to the latest page marker, keeping the UX better.
This just feels hacky, and I feel like I’m missing something more simple to keep the scroll from behaving this way. Any thoughts would be appreciated!
2
Answers
I would try to save the position before loading the new messages and then scroll to that. Something like:
You have to keep saving messages in batches tho, so maybe not with different divs (with page number as id like you’re doing) but with an array of objects with ids and content (so that you know what to load when scrolling reaches top).
CSS Overflow Scroll.