每次用户php files using ajax
窗口时,我都会附加一些scrolls to the bottom
。
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() > $(document).height() - 100){
$(window).unbind('scroll');
// Function to append php files using ajax
}
})
我想知道下次用户滚动到页面底部并附加一些其他php文件,但是如何找到滚动到页面底部的下一个(1个或多个)事件?
Example: First scroll to bottom: Append 1.php 2.php
second scroll to bottom: append 3.php 4.php
third scroll to bottom: append 5.php 6.php
4th scroll to bottom: show footer
我不需要infinite scroll plugin
。因为那里没有footer
的概念。
答案 0 :(得分:1)
您需要维护一个计数器变量来计算您已经完成的请求数量。然后,您可以将其传递给服务器,然后服务器将返回所需的信息。像这样:
var requestCount = 0;
$(window).scroll(function(){
if ($(window).scrollTop() + $(window).height() > $(document).height() - 100) {
$(window).unbind('scroll');
// Function to append php files using ajax
requestCount++;
if (requestCount < 4) {
$.ajax({
url: 'foo.php',
data: { page: requestCount },
success: function() {
// append your items
}
}
}
else {
// show footer
}
}
})
在PHP中,您需要使用page
变量并返回相关项目。
答案 1 :(得分:0)
var count = 1;
$(window).scroll(function(){
if($(window).scrollTop() + $(window).height() > $(document).height() - 100){
$(window).unbind('scroll');
if(count<4)
// Function to append php files using ajax
call_your_ajax_with_url(count+'.php');
call_your_ajax_with_url(count+1 +'.php');
count+=1;
else showFooter();
}
});
会做这项工作。