Skip to content

Instantly share code, notes, and snippets.

@qgustavor
Created February 25, 2014 15:51
Show Gist options
  • Save qgustavor/9211594 to your computer and use it in GitHub Desktop.
Save qgustavor/9211594 to your computer and use it in GitHub Desktop.
Scroll infinito
window.onscroll = function onScroll() {
var htmlEl = document.documentElement,
alturaJanela = htmlEl.clientHeight,
alturaTotal = Math.max(document.body.scrollHeight, htmlEl.scrollHeight, document.body.offsetHeight, htmlEl.offsetHeight, htmlEl.clientHeight);
// Aplique a lógica que quiser, usei: se o scroll
if(alturaTotal - 2 * alturaJanela < window.scrollY) {
carregarDados();
}
window.onscroll = null;
setTimeout(function () {
window.onscroll = onScroll;
}, 250)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment