Skip to content

Instantly share code, notes, and snippets.

@6ui11em
Created December 11, 2013 20:20
Show Gist options
  • Save 6ui11em/7917730 to your computer and use it in GitHub Desktop.
Save 6ui11em/7917730 to your computer and use it in GitHub Desktop.
JQuery: Smooth Scroll
$('.scrollto').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
|| location.hostname == this.hostname) {
var hashStr = this.hash.slice(1);
var target = $(this.hash);
target = target.length ? target : $('[name=' + hashStr +']');
if (target.length) {
$('html,body').animate({ scrollTop: target.offset().top - 20}, 500);
window.location.hash = hashStr;
return false;
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment