Skip to content

Instantly share code, notes, and snippets.

@Eworm
Created June 26, 2013 12:22
Show Gist options
  • Save Eworm/5866977 to your computer and use it in GitHub Desktop.
Save Eworm/5866977 to your computer and use it in GitHub Desktop.
Scroll to function because 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
scrollTo = parseInt(scrollTo);
time /= runEvery;
var 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