Last active
October 2, 2019 08:14
-
-
Save jbutko/8206861 to your computer and use it in GitHub Desktop.
jQuery: JQuery smooth scrolling when clicking an anchor link
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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 |
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
really simple and efficient code, gw.