Skip to content

Instantly share code, notes, and snippets.

@pensart
Last active February 24, 2017 08:28
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 pensart/70e4e806a12ccaecbf1a76f579bda712 to your computer and use it in GitHub Desktop.
Save pensart/70e4e806a12ccaecbf1a76f579bda712 to your computer and use it in GitHub Desktop.
Smooth scroll on # targets and show no hash in the url
// 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