Last active
August 29, 2015 14:14
-
-
Save maxxscho/39a4b3e336f25caec8ed to your computer and use it in GitHub Desktop.
jQuery Autoscroll on hashed links
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
// Auto scroll | |
// ------------------------------------- | |
$('a[href^=#]').on('click', function(e) { | |
e.preventDefault(); | |
var $this = $(this), | |
target = $this.attr('href'); | |
if(target && target !== "#") { | |
$('html, body').animate({ | |
scrollTop: $(target).offset().top | |
}, 600); | |
} | |
return false; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment