[英]load more when scroll work two time at once when scroll in speed
嗨,我正在使用ajax滾動分頁,當我滾動頁面兩次使其工作速度滾動並且兩次滾動其工作兩次時,它發送相同的id兩次,並且對結果有效,我該如何解決這個問題? 這是我的劇本
$(document).ready(function(){
function last_msg_funtion()
{
var IDall=$(".box-mainb:last").attr("id");
var cbid=$(".box-mainp:last").attr("id");
$('div#last_msg_loaderi').html('<img src="bigLoader.gif">');
$.get('page.php', {'action':'get','last_msg_id':IDall,'id':cbid},
function(dataz){
if (dataz != "") {
$(".box-mainb:last").after(dataz);
}
$('div#last_msg_loaderi').empty();
});
};
$(window).scroll(function(){
if ($(window).scrollTop() == $(document).height() - $(window).height()){
last_msg_funtion();
}
});
});
一種解決方案是使用一個標志來檢查是否已經在進行另一個滾動操作,例如
$(document).ready(function () {
var loading = false;
function last_msg_funtion() {
var IDall = $(".box-mainb:last").attr("id");
var cbid = $(".box-mainp:last").attr("id");
$('div#last_msg_loaderi').html('<img src="bigLoader.gif">');
loading = true;
$.get('page.php', {
'action': 'get',
'last_msg_id': IDall,
'id': cbid
}, function (dataz) {
if (dataz != "") {
$(".box-mainb:last").after(dataz);
}
$('div#last_msg_loaderi').empty();
}).always(function () {
loading = false;
});
};
$(window).scroll(function () {
if (loading) {
return;
}
if ($(window).scrollTop() == $(document).height() - $(window).height()) {
last_msg_funtion();
}
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.