關(guān)鍵代碼:
復制代碼 代碼如下:
var stop=true;
$(window).scroll(function(){
totalheight = parseFloat($(window).height()) + parseFloat($(window).scrollTop());
if($(document).height() <= totalheight){
if(stop==true){
stop=false;
$.post("ajax.php", {start:1, n:50},function(txt){
$("#Loading").before(txt);
stop=true;
},"text");
}
}
});
HTML:
復制代碼 代碼如下:
<div>Loading...</div>
實現(xiàn)方法是比較頁面總高度和下滾高度以判斷是否到達底端,若到達底端則通過ajax讀取更多的內(nèi)容,用before插入到Loading之前。
stop參數(shù)是考慮到ajax讀取耗時,防止在一次ajax讀取過程中多次觸發(fā)事件,造成多次加載內(nèi)容。
新聞熱點
疑難解答
圖片精選