我有一个无限的滚动分页脚本,它包含在一个setInterval()函数中,每隔x秒附加一次新数据,两个函数都运行正常,但是每次我开始滚动时,一旦setInterval()刷新,我会得到无限滚动分页损坏div,有没有办法阻止setInterval()运行,只要我滚动?
这是我的代码:
$(document).ready(function(){
$.ajaxSetup({ cache: false });
setInterval(function(){
var track_load = 0;
var loading = false;
var total_groups = <?php echo $total_groups; ?>;
$('#live_activity').load("loading_page.php", {'group_no':track_load}, function() {track_load++;});
$(window).scroll(function() {
if($(window).scrollTop() + $(window).height() == $(document).height())
{
if(track_load <= total_groups && loading==false)
{
loading = true;
$('.animation_image').show();
$.post('loading_page.php',{'group_no': track_load}, function(data){
$("#live_activity").append(data);
//hide loading image
$('.animation_image').hide();
track_load++;
loading = false;
}).fail(function(xhr, ajaxOptions, thrownError) {
alert(thrownError);
$('.animation_image').hide();
loading = false;
});
}
}
});
}, 3000);
});