jQuery - Smooth anchor scrolling


/ Published in: JavaScript
Save to your folder(s)

Detects all anchor links in a page and makes them go to the place smoothly.


Copy this code and paste it in your HTML
  1. var scrollWin = function (selector) {
  2. $('html, body').animate({
  3. scrollTop: $(selector).offset().top
  4. }, 2000);
  5. }
  6.  
  7. $("[href^=#]").click(function(e) {
  8. scrollWin ($(this).attr("href"));
  9. return false;
  10. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.