Skip to content

Instantly share code, notes, and snippets.

View andythedandy's full-sized avatar
😶‍🌫️
R.I.P. elseym

Andy Eberle-Bannert andythedandy

😶‍🌫️
R.I.P. elseym
View GitHub Profile
@andythedandy
andythedandy / zepto.smoothScroll.js
Last active February 26, 2016 12:22 — forked from austinpray/zepto.smoothScroll.js
Zepto.js smooth vertical scrolling method. Implementing this code turns all anchor links into smooth scrolling anchor links.
function smoothScroll(el, to, duration) {
if (duration < 0) {
return;
}
var difference = to - $(window).scrollTop();
var perTick = difference / duration * 10;
$(this).scrollToTimerCache = setTimeout(function() {
if (!isNaN(parseInt(perTick, 10))) {
window.scrollTo(0, $(window).scrollTop() + perTick);
smoothScroll(el, to, duration - 10);