Skip to content

Instantly share code, notes, and snippets.

@raullucero
Last active July 21, 2017 23:41
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 raullucero/0968d5f8f39bd453b2861efce4a65e78 to your computer and use it in GitHub Desktop.
Save raullucero/0968d5f8f39bd453b2861efce4a65e78 to your computer and use it in GitHub Desktop.
// PROBLEMA: hacer un infinite scroll y obtener mas datos e agregarlos a la lista
// Initial
$(window).on('scroll', scrollHandler);
function scrollHandler () {
}
// html
// <ul id="posts"></ul>
$(window).on('scroll', scrollHandler);
function scrollHandler () {
var scrollHeight = window.scrollHeight;
var scrollTop = window.scrollTop;
var height = window.offsetHeight;
if (scrollTop === (scrolHeight - height)) {
getMoreData();
}
}
function getMoreData() {
return request(req).then(res => {
var list = res.map(item => `<li>${item}</li>`).join('');
var posts = document.getElementById('posts');
posts.innerHTML += list;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment