4

I'm trying to scroll down to the bottom of the page when a new message is received or sent, I have everything set up and it's working fine on my laptop but when I try accessing my website on a mobile device the scroll event is not working.

Well I have used both of jQuery scroll, and pure javascript scroll but none of them worked on the mobile device

Here are all the functions that I used which I found all across the internet:

//first method
window.scrollTo(0,document.body.scrollHeight);

//second method
$("html,body").animate({
    scrollTop: $(document).height()
}, "slow");

//third method
$('my-messages-container').animate({ scrollTop : $(document).height()+1000000 });

well, the code is working fine when I use the developer tools mobile simulation. but when I try it on a real mobile device it doesn't work.

Moshe Slavin
  • 5,127
  • 5
  • 23
  • 38
FiAi
  • 41
  • 6

2 Answers2

1
elementAtBottomOfPage.scrollIntoView()

Is what finally ended up working for me, on iOS.

https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView

Ronald C
  • 171
  • 6
-1

As stated on: jQuery Scroll To bottom of the page

$("html, body").animate({scrollTop: $(document).height()-$(window).height()}); 

Would get you to the bottom of the page.

Findegil
  • 82
  • 3