Created
June 26, 2013 12:22
-
-
Save Eworm/5866977 to your computer and use it in GitHub Desktop.
Scroll to function because zepto doesn't have scrolltop animation
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
// 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