Skip to content

Instantly share code, notes, and snippets.

@Ajax30
Last active September 5, 2016 19:40
Show Gist options
  • Save Ajax30/96e8bedb1ab30a14a89c3c821eb2417f to your computer and use it in GitHub Desktop.
Save Ajax30/96e8bedb1ab30a14a89c3c821eb2417f to your computer and use it in GitHub Desktop.
Infinite scroll to load PHP files
function loadNewItems(){
var win = $(window);
var scrollCount = 0;
// Bind window scroll event
win.scroll(function() {
// If End of document reached
if ($(document).height() - win.height() == win.scrollTop()) {
// path to the file containing the code to load
var pageToLoad = '/get-items.php' + "?p=" + scrollCount;
$.ajax({
url: pageToLoad,
dataType: 'html',
success: function(html) {
$(html).insertBefore("#loading");
$('.video-list .item.loaded').fadeIn(250);
$('#loading').hide();
scrollCount++;
}
});
}
});
}
loadNewItems();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment