Skip to content

Instantly share code, notes, and snippets.

@besimhu
Last active August 29, 2015 14:17
Show Gist options
  • Save besimhu/83628046772205165c0b to your computer and use it in GitHub Desktop.
Save besimhu/83628046772205165c0b to your computer and use it in GitHub Desktop.
Smooth scroll any hashtag link to their ID.
// Smooth scroll to content
$('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') || location.hostname == this.hostname) {
var targetH = $(this.hash),
target = targetH.length ? targetH : $('[name=' + this.hash.slice(1) +']');
if (target.length) {
$('html,body').animate({
scrollTop: target.offset().top - 60
}, 600);
return false;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment