Created
December 2, 2019 10:34
-
-
Save antimatter96/db91d1c36b077d683ffbb9856afe39d6 to your computer and use it in GitHub Desktop.
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
var dir = "down"; | |
var babyScroll; | |
var stepTime = 1; | |
var downLimit = document.documentElement.scrollHeight - document.documentElement.clientHeight; | |
var upLimit = 0; | |
function babyScroll() { | |
if(dir == "down") { | |
window.scrollTo(0, window.scrollY + 10); | |
if (window.scrollY >= downLimit - 1) { | |
clearInterval(babyScrollId); | |
dir = "up"; | |
babyScrollId = setInterval(babyScroll, stepTime); | |
} | |
} else { | |
window.scrollTo(0, window.scrollY - 10); | |
if (window.scrollY <= upLimit) { | |
clearInterval(babyScrollId); | |
dir = "down"; | |
babyScrollId = setInterval(babyScroll, stepTime); | |
} | |
} | |
}; | |
var babyScrollId = setInterval(babyScroll, stepTime); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment