Skip to content

Instantly share code, notes, and snippets.

@RomkeVdMeulen
Created July 30, 2016 14:38
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 RomkeVdMeulen/e3c48dbb3f3af5624f726ffd6c18c87c to your computer and use it in GitHub Desktop.
Save RomkeVdMeulen/e3c48dbb3f3af5624f726ffd6c18c87c to your computer and use it in GitHub Desktop.
Smooth scrolling to anchors using jQuery
$('a').click(function(ev){
href = this.href.replace(window.location.href,'');
if ( href[0] != '#' || !$(href) ) {
return;
}
$('html, body').animate({ scrollTop: $(href).offset().top }, 500);
ev.stopPropagation();
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment