Skip to content

Instantly share code, notes, and snippets.

@djom202
Created August 10, 2015 13:35
Show Gist options
  • Select an option

  • Save djom202/772049c83084d56a165e to your computer and use it in GitHub Desktop.

Select an option

Save djom202/772049c83084d56a165e to your computer and use it in GitHub Desktop.
Nav to Hash on click
$("#nav ul li a[href^='#']").on('click', function(e) {
// prevent default anchor click behavior
e.preventDefault();
// store hash
var hash = this.hash;
// animate
$('html, body').animate({
scrollTop: $(hash).offset().top
}, 300, function(){
// when done, add hash to url
// (default click behaviour)
window.location.hash = hash;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment