Last active
September 5, 2016 19:40
-
-
Save Ajax30/96e8bedb1ab30a14a89c3c821eb2417f to your computer and use it in GitHub Desktop.
Infinite scroll to load PHP files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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