Created
June 15, 2016 19:14
-
-
Save townivan/3be437575b70acbb8ce9e2a966aa33d6 to your computer and use it in GitHub Desktop.
This file contains 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
// source: https://jonsuh.com/blog/better-scroll-to-anchor-links/ | |
$(".anchorLink").click(function(e){ | |
e.preventDefault(); | |
var this_offset = $(this).offset(); | |
var that_id = $(this).attr("href"); | |
var that_offset = $(that_id).offset(); | |
var offset_diff = Math.abs(that_offset.top - this_offset.top); | |
var base_speed = 100; // Time in ms per 1,000 pixels | |
var speed = (offset_diff * base_speed) / 1000; | |
$("html,body").animate({ | |
scrollTop: that_offset.top | |
}, speed); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment