Skip to content

Instantly share code, notes, and snippets.

@tjhole
Created November 26, 2013 22:54
Show Gist options
  • Save tjhole/7667792 to your computer and use it in GitHub Desktop.
Save tjhole/7667792 to your computer and use it in GitHub Desktop.
JQUERY: Smooth Scroll
var $s = jQuery.noConflict();
$s(function() {
$s('a[href*=#]:not([href=#])').click(function() {
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
|| location.hostname == this.hostname) {
var target = $s(this.hash);
target = target.length ? target : $s('[name=' + this.hash.slice(1) +']');
if (target.length) {
$s('html,body').animate({
scrollTop: target.offset().top
}, 1000);
return false;
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment