Created
December 11, 2013 20:20
-
-
Save 6ui11em/7917730 to your computer and use it in GitHub Desktop.
JQuery: Smooth Scroll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('.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