$(window).scroll(function() { var scrollTop = $(this).scrollTop(); //滾動條距離頂部的高度 var scrollHeight = $(document).height(); //當前頁面的總高度 var clientHeight = $(this).height(); //當前可視的頁面高度 if (scrollTop + clientHeight >= scrollHeight - 50) { getData(); // 請求數據 } })
window.onscroll = function() {
//獲取被卷去高度
var scrollTop = document.body.scrollTop;
//獲取窗口高度(可見區域高度)
var windowHeight = document.documentElement.clientHeight;
//獲取文檔高度
var documentHeight = document.body.scrollHeight;
if (scrollTop + windowHeight >= documentHeight - 50) {
$('#nomore').show();
//發送Ajax請求獲取分頁數據
}
}
/** * 得到瀏覽器顯示的屏幕高度 */ function getViewHeight() { if (window.innerHeight != window.undefined) return window.innerHeight; if (document.compatMode == 'CSS1Compat') return document.documentElement.clientHeight; if (document.body) return document.body.clientHeight; return window.undefined; } /** * 得到瀏覽器顯示的屏幕寬度 */ function getViewWidth() { if (window.innerWidth != window.undefined) return window.innerWidth; if (document.compatMode == 'CSS1Compat') return document.documentElement.clientWidth; if (document.body) return document.body.clientWidth; }