Smooth Scrolling Links to the Top of the Page

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");
});
 

Mark Ursino

Mark is Sr. Director, CMS Practice Lead at Rightpoint and a Sitecore Technology MVP.

 

Leave a Reply

Your email address will not be published. Required fields are marked *