Last active
February 24, 2017 08:28
-
-
Save pensart/70e4e806a12ccaecbf1a76f579bda712 to your computer and use it in GitHub Desktop.
Smooth scroll on # targets and show no hash in the url
This file contains 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
// Warning, this wil target all # elements | |
// Even when they do not link to a location on the page | |
// For example, #next-arrow will also prevent the default behavior | |
$('a[href^="#"]').on('click', function (e) { | |
e.preventDefault(); | |
var target = this.hash; | |
var $target = $(target); | |
$('html, body').animate({ | |
'scrollTop': $target.offset().top | |
}, 500, 'swing'); | |
}); // - end Smooth scroll |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment