Skip to content

Instantly share code, notes, and snippets.

@ryanapil
Created April 8, 2018 19:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
jQuery smooth scroll to # links
$(document).ready(function() {
$("a[href^='#']").on("click", function(event) {
event.preventDefault();
var target = this.hash,
$target = $(target);
$("html, body").stop().animate({
"scrollTop": $target.offset().top
}, 900, "swing", function() {
window.location.hash = target;
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment