jQuery實現滾動條動態載入
阿新 • • 發佈:2019-01-29
//滾動條載入底部自動載入 $(function(){ //滑鼠滾動事件 $(window).scroll(function(){ console.log("滾動條到頂部的垂直高度:" + $(window).scrollTop() ); console.log("頁面的文件高度:" + $(document).height() ); console.log("瀏覽器的高度:" + $(window).height() ); //下面這句主要是獲取網頁的總高度,主要是考慮相容性所以把Ie支援的documentElement也寫了,這個方法至少支援IE8 var htmlHeight=document.body.scrollHeight||document.documentElement.scrollHeight; //clientHeight是網頁在瀏覽器中的可視高度, var clientHeight=document.body.clientHeight||document.documentElement.clientHeight; //scrollTop是瀏覽器滾動條的top位置, var scrollTop=document.body.scrollTop||document.documentElement.scrollTop; //通過判斷滾動條的top位置與可視網頁之和與整個網頁的高度是否相等來決定是否載入內容;if(scrollTop+clientHeight==htmlHeight){ start+=length; findBookList(start,length); // 延時 // setTimeout(function () { // // },1000) } })