Skip to content

Instantly share code, notes, and snippets.

@Patrick64
Created June 4, 2019 10:41
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 Patrick64/44ba3f218d40ee00338f4f12c9798b11 to your computer and use it in GitHub Desktop.
Save Patrick64/44ba3f218d40ee00338f4f12c9798b11 to your computer and use it in GitHub Desktop.
function smoothAnchorScroll() {
// https://www.abeautifulsite.net/smoothly-scroll-to-an-element-without-a-jquery-plugin-2
$('a[href*="#"]').on('click', function(event) {
if (this.getAttribute('href') == "#") return;
var target = $(this.getAttribute('href'));
if( target.length ) {
// event.preventDefault();
$('html, body').stop().animate({
scrollTop: target.offset().top
}, 1000);
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment