Skip to content

Instantly share code, notes, and snippets.

@jbutko
Last active October 2, 2019 08:14
Show Gist options
  • Save jbutko/8206861 to your computer and use it in GitHub Desktop.
Save jbutko/8206861 to your computer and use it in GitHub Desktop.
jQuery: JQuery smooth scrolling when clicking an anchor link
$('a').click(function(){
$('html, body').animate({
scrollTop: $( $.attr(this, 'href') ).offset().top
}, 500);
return false;
});
// http://stackoverflow.com/questions/7717527/jquery-smooth-scrolling-when-clicking-an-anchor-link/7717572#7717572?newreg=16ca424bc4024b21a4fcc728ea6451d5
@YanwillRivera
Copy link

really simple and efficient code, gw.

@beto-aveiga
Copy link

As far as I know, you should only do preventDefault, not return false which may have side effects. Please check https://css-tricks.com/dangers-stopping-event-propagation/ and update accordingly.
Thanks for sharing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment