Skip to content

Instantly share code, notes, and snippets.

@Farmatique
Created September 26, 2016 12:52
Show Gist options
  • Save Farmatique/4c79d40b969ae773da096782e02d29fe to your computer and use it in GitHub Desktop.
Save Farmatique/4c79d40b969ae773da096782e02d29fe to your computer and use it in GitHub Desktop.
smooth scroll to section
jQuery(document).on('click', 'a[href*="#"]:not([href="#"])', function(e) {
if (location.pathname.replace(/^\//,'') === this.pathname.replace(/^\//,'') && location.hostname === this.hostname) {
var target = jQuery(this.hash);
target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
jQuery('html, body').animate({
scrollTop: target.offset().top
}, 1000);
e.preventDefault();
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment