Skip to content

Instantly share code, notes, and snippets.

@qgustavor
Created February 25, 2014 15:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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