11-09-2009

jQuery Scroll to top with animate function

To scroll to top of the page with jQuery use the following:

$('html,body').animate({scrollTop: 0}, 500);

to animate - scroll to an element on the page calculate it's top offset and then scroll to that:

$('html,body').animate({scrollTop: $("#someContainer").offset().top}, 500);
 

If you just want to scroll to somewhere in the page as quickly as possible without animation use the scrollTop method.

$('html,body').scrollTop($("#someContainer").offset().top);
 

Comments:

Your comment:

»

 

[x]