Skip to content

Instantly share code, notes, and snippets.

@pmulik34
Created July 24, 2021 10:04
Show Gist options
  • Save pmulik34/aa1034ea8f00d8315931f4d603b447c3 to your computer and use it in GitHub Desktop.
Save pmulik34/aa1034ea8f00d8315931f4d603b447c3 to your computer and use it in GitHub Desktop.
let scrollerID;
let paused = true;
let speed = 2; // 1 - Fast | 2 - Medium | 3 - Slow
let interval = speed * 5;
function startScroll(){
let id = setInterval(function() {
window.scrollBy(0, 2);
if ((window.innerHeight + window.scrollY) >= document.body.offsetHeight) {
// Reached end of page
stopScroll();
}
}, interval);
return id;
}
function stopScroll() {
clearInterval(scrollerID);
}
document.body.addEventListener('keypress', function (event)
{
if (event.which == 13 || event.keyCode == 13) {
if(paused == true) {
scrollerID = startScroll();
paused = false;
}
else {
stopScroll();
paused = true;
}
}
}, true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment