How do I set the view to the page's bottom on entering the page?

Viewed 56

I have a page that represents a chat in my Angular-Ionic project. When the user opens the chat, I would like the view to already be scrolled all the way down to the latest message.

I have tried using ionContent.scrollToBottom(0) in a setTimeout (since the content doesn't load right away) but it's pretty awkward: it very briefly shows the top of the messages and then teleports to the bottom, making it look super ugly.

I am using Angular 10 and Ionic 5.

Does anyone have a better solution?

1 Answers

Use window.onload = function() {window.scrollTo(0,document.body.scrollHeight);}.

Hope it helped!

Related