Created
December 17, 2013 01:54
-
-
Save zackn9ne/7998648 to your computer and use it in GitHub Desktop.
Smooth Scroll with Offset
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