jQuery Scroll To bottom of the page

AnApprentice picture AnApprentice · Nov 22, 2010 · Viewed 466k times · Source

After my page is done loading. I want jQUery to nicely scroll to the bottom of the page, animating quickly, not a snap/jolt.

Do iI need a plugin like ScrollTo for that? or is that built into jQuery some how?

Answer

Nick Craver picture Nick Craver · Nov 22, 2010

You can just animate to scroll down the page by animating the scrollTop property, no plugin required, like this:

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

Note the use of window.onload (when images are loaded...which occupy height) rather than document.ready.

To be technically correct, you need to subtract the window's height, but the above works:

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

To scroll to a particular ID, use its .scrollTop(), like this:

$("html, body").animate({ scrollTop: $("#myID").scrollTop() }, 1000);