Created
April 13, 2020 14:23
-
-
Save MatheusMuriel/f91e13c5adb6462f2eb6a4ab6473405d to your computer and use it in GitHub Desktop.
Scroll até o limite máximo da pagina
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
// Scroll para o fim da pagina | |
// Esse script é feito para scrollar até o fim de paginas com loading | |
// Eu o programei para ir até o final da pagina do instagram web | |
// mas creio que possa ser usado em diversos cenarios por isso estou compartilhando | |
// Caso ele pare antes de chegar ao final tente aumentar o tempo do sleep na linha 12 | |
const sleep = (ms) => { return new Promise(resolve => setTimeout(resolve, ms)) } | |
var isEndOfPage = false; | |
while (!isEndOfPage) { | |
let heightBegin = document.body.scrollHeight; | |
window.scrollTo(0 , document.body.scrollHeight); | |
await sleep(2000); | |
let heightActual = document.body.scrollHeight; | |
isEndOfPage = (heightBegin === heightActual); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment