我有以下代碼,用戶在滾動到頁面底部時加載內容。問題是,如果一個人滾動太快,它會加載內容。我可以通過哪些方式更改我的代碼以防止此問題?從雙重加載內容停止.ajax
$(window).scroll(function(){
if($(window).scrollTop() == $(document).height() - $(window).height()){
$('div#ajaxResults').show();
$.ajax({
url: "ajax/home.php?last_id=" + $(".postitem:last").attr("id"),
success: function(html){
if(html){
$("#messages").append(html);
$('#ajaxResults').hide();
}else{
$('#ajaxResults').html('<center>None.</center>');
}
}
});
}
});
我需要解決方案多次工作。該腳本加載了接下來的5條消息,但可能會加載數百條消息。它應該以與Facebook或Twitter加載更新相同的方式工作。
將超過兩倍...滾動事件觸發100秒的時間,你需要一個緩存機制 – charlietfl 2012-03-02 04:04:09