2

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?

arcrub
  • 170
  • 1
  • 11
  • 1
    This might help: [https://stackoverflow.com/questions/11715646/scroll-automatically-to-the-bottom-of-the-page](https://stackoverflow.com/questions/11715646/scroll-automatically-to-the-bottom-of-the-page) – Rob Moll Jan 07 '21 at 18:16
  • I'd still use Ionic's scrollToBottom and show a loader if the pause bothers you. – 1x2x3x4x Jan 18 '21 at 16:32

1 Answers1

0

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

Hope it helped!

Willian
  • 98
  • 11