How do I use jquery to scroll right down to the bottom of an iframe or page?
How do I use jquery to scroll right down to the bottom of an iframe or page?
If you want a nice slow animation scroll, for any anchor with href="#bottom" this will scroll you to the bottom:
$("a[href='#bottom']").click(function() {
$("html, body").animate({ scrollTop: $(document).height() }, "slow");
return false;
});
Feel free to change the selector.
$('.block').scrollTop($('.block')[0].scrollHeight);
I use this code to scroll the chat when new messages arrive.
The scripts mentioned in previous answers, like:
$("body, html").animate({
scrollTop: $(document).height()
}, 400)
or
$(window).scrollTop($(document).height());
will not work in Chrome and will be jumpy in Safari in case html tag in CSS has overflow: auto; property set. It took me nearly an hour to figure out.