Skip to content

How to Scroll to the Bottom when new content arrives #2854

Answered by masenf
masenf asked this question in Q&A
Discussion options

You must be logged in to vote

Using the reflex-intersection-observer component, along with the scrollIntoView() function supported by most browsers, you can have a hidden 1px div at the bottom of your message list, and when it goes out of view, trigger an event handler to automatically scroll the hidden div back into view, once.

This has the nice side effect of allowing your users to scroll up in the messages without automatically scrolling back down when a new message arrives, but re-enabling the auto scroll to bottom if they do scroll it back down to the latest message.

It has one unfortunate side effect of a tiny little jitter when initially scrolling up, because the component will try to scroll back down the first…

Replies: 1 comment

Comment options

masenf
Mar 13, 2024
Maintainer Author

You must be logged in to vote
0 replies
Answer selected by masenf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant