Skip to content

Instantly share code, notes, and snippets.

View alexanderkraemer's full-sized avatar

Alexander Krämer alexanderkraemer

View GitHub Profile

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@alexanderkraemer
alexanderkraemer / zepto.smoothScroll.js
Last active September 10, 2015 20:37 — forked from felipefialho/zepto.smoothScroll.js
Zepto.js smooth vertical scrolling method. Implementing this code turns all anchor links with the class "scrollTo" into smooth scrolling anchor links. Rework of the foundation.js library method.
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);