Skip to content

Instantly share code, notes, and snippets.

@antimatter96
Created December 2, 2019 10:34
Show Gist options
  • Save antimatter96/db91d1c36b077d683ffbb9856afe39d6 to your computer and use it in GitHub Desktop.
Save antimatter96/db91d1c36b077d683ffbb9856afe39d6 to your computer and use it in GitHub Desktop.
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