方法1:
$(window).scroll(function(){
var scrollTop = $(this).scrollTop();var scrollHeight = $(document).height();
var windowHeight = $(this).height();
if(scrollTop + windowHeight == scrollHeight){
nearbyData();//加载数据的函数
}
});
方法2:
var $window = $(window);
var $document = $(document);
function onScroll() {
// 如果窗口底部小于1像素,就执行加载事件
var winHeight = window.innerHeight ? window.innerHeight : $window.height(), // iphone fix
closeToBottom = ($window.scrollTop() + winHeight > $document.height() - 0.00000000001);
if (closeToBottom) {
nearbyData();
}
}
$window.bind('scroll', onScroll);