-
-
Save dgmike/9478658 to your computer and use it in GitHub Desktop.
Scroll function cause 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 | |
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