-
-
Notifications
You must be signed in to change notification settings - Fork 3
Infite Scroll
Wesley de Groot edited this page Nov 7, 2017
·
3 revisions
Demo: Infite scroll.
//var listElm = document.querySelector('#infinite-list');
var listElm = _('#infinite-list');
// Add 20 items.
var nextItem = 1;
var loadMore = function() {
for (var i = 0; i < 20; i++) {
var item = document.createElement('li');
item.innerText = 'Item ' + nextItem++;
listElm.appendChild(item);
}
}
// Detect when scrolled to bottom.
listElm.addEventListener('scroll', function() {
if (listElm.scrollTop + listElm.clientHeight >= listElm.scrollHeight) {
loadMore();
}
});
// Initially load some items.
loadMore();
EOF.
© Wesley de Groot • CC-BY 4.0 • WDGWV