Last active
December 20, 2021 16:34
-
-
Save cnscorpions/40797369d2105f009c2650f267692efb to your computer and use it in GitHub Desktop.
Scroll to webpage bottom
This file contains hidden or 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 to bottom | |
* @param {*} page | |
*/ | |
(async () => { | |
await new Promise((resolve, reject) => { | |
var totalHeight = 0; | |
var distance = 400; | |
var timer = setInterval(() => { | |
var scrollHeight = document.body.scrollHeight; | |
window.scrollBy(0, distance); | |
totalHeight += distance; | |
if (totalHeight >= scrollHeight) { | |
clearInterval(timer); | |
resolve(); | |
} | |
}, 1000); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment