Last active
July 12, 2024 04:06
-
-
Save sabapathygithub/e6ca2c0fd06c21c5fb608b9a172ca3c4 to your computer and use it in GitHub Desktop.
Auto scroll to bottom of the page in JavaScript with smooth scrolling based on time delay.
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
function scrollToBottom(timedelay=0) { | |
var scrollId; | |
var height = 0; | |
var minScrollHeight = 100; | |
scrollId = setInterval(function () { | |
if (height <= document.body.scrollHeight) { | |
window.scrollBy(0, minScrollHeight); | |
} | |
else { | |
clearInterval(scrollId); | |
} | |
height += minScrollHeight; | |
}, timedelay); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Very usefull, thanks!