Skip to content

Instantly share code, notes, and snippets.

@eivko
Created August 11, 2020 11:38
Show Gist options
  • Save eivko/f870f4373989ae454d3aa70ee0f4f3e2 to your computer and use it in GitHub Desktop.
Save eivko/f870f4373989ae454d3aa70ee0f4f3e2 to your computer and use it in GitHub Desktop.
Scroll to the selected anchor
$('a[href^="#"]').on('click', function(event) {
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