Skip to content

Instantly share code, notes, and snippets.

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 Ginnw2/0b58952056303d96e8348aa778000bf1 to your computer and use it in GitHub Desktop.
Save Ginnw2/0b58952056303d96e8348aa778000bf1 to your computer and use it in GitHub Desktop.
$(document).on('click', 'a[href^="#"]', function(e) {
// target element id
var id = $(this).attr('href');
// target element
var $id = $(id);
if ($id.length === 0) {
return;
}
// prevent standard hash navigation (avoid blinking in IE)
e.preventDefault();
// top position relative to the document
var pos = $id.offset().top;
// animated top scrolling
$('body, html').animate({scrollTop: pos}, 1000);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment