Smooth Scrolling Links to the Top of the Page

Jan 1, 2011 by Mark Ursino    No Comments    Posted under: jQuery

Here’s a useful snippet of reusable code to use jQuery to smoothly scroll to the top of the page. I first wrote it in response to a question on Stack Overflow. It finds any anchor with href equal to #top.

$("a[href='#top']").click(function(e) {
  e.preventDefault();
  $("html").animate({ scrollTop: 0 }, "slow");
});

Got anything to say? Go ahead and leave a comment!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

 

Categories