Skip to content

Instantly share code, notes, and snippets.

@dgmike
Forked from Eworm/gist:5866977
Last active September 16, 2019 11:05
Show Gist options
  • Save dgmike/9478658 to your computer and use it in GitHub Desktop.
Save dgmike/9478658 to your computer and use it in GitHub Desktop.
Scroll function cause zepto doesn't have scrolltop animation
// Scroll function cause zepto doesn't have scrolltop animation
;function scrollNew(scrollTo, time) {
var scrollFrom = parseInt(document.body.scrollTop),
i = 0,
runEvery = 5, // run every 5ms
time = time || 1000,
interval
;
scrollTo = parseInt(scrollTo);
time = time / runEvery;
interval = setInterval(function () {
i++;
document.body.scrollTop = (scrollTo - scrollFrom) / time * i + scrollFrom;
document.documentElement.scrollTop = (scrollTo - scrollFrom) / time * i + scrollFrom;
if (i >= time) {
clearInterval(interval);
}
}, runEvery);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment