Skip to content

Instantly share code, notes, and snippets.

@maxxscho
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxxscho/39a4b3e336f25caec8ed to your computer and use it in GitHub Desktop.
Save maxxscho/39a4b3e336f25caec8ed to your computer and use it in GitHub Desktop.
jQuery Autoscroll on hashed links
// 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