我找到了这个无限滚动脚本。它有效,但我不明白这一行:
'contentData': {}, // you can pass the children().size() to know where is the pagination
当我将其更改为以下内容时:
'contentData': {xyz:($('#content').children().size())},
每次的值都是一样的。在我的示例中,当我alert(($('#content').children().size()))
在该afterLoad
部分中调用时,该值是正确的(在每个滚动事件上都不同)。我不明白如何设置contentData
为不同的值(比如第一次加载时为 10,第二次加载时为 20,等等)。
这是我的脚本:
$(function(){
$('#content').scrollPagination({
'contentPage': '/democontent.php', // the page where you are searching for results
'contentData': {xyz:($('#content').children().size())}, // you can pass the children().size() to know where is the pagination
'scrollTarget': $(window), // who gonna scroll? in this example, the full window
'heightOffset': 10, // how many pixels before reaching end of the page would loading start? positives numbers only please
'beforeLoad': function(){ // before load, some function, maybe display a preloader div
$('#loading').fadeIn();
},
'afterLoad': function(elementsLoaded){ // after loading, some function to animate results and hide a preloader div
$('#loading').fadeOut();
var i = 0;
$(elementsLoaded).fadeInWithDelay();
alert(($('#content').children().size()));
if ($('#content').children().size() > 10000){ // if more than 100 results loaded stop pagination (only for test)
$('#nomoreresults').fadeIn();
$('#content').stopScrollPagination();
}
}
});
// code for fade in element by element with delay
$.fn.fadeInWithDelay = function(){
var delay = 0;
return this.each(function(){
$(this).delay(delay).animate({opacity:1}, 200);
delay += 100;
});
};
});