0

我一直在尝试检测用户滚动何时到达底部

我有下面的代码。

if  ($(window).scrollTop() == ($(document).innerHeight() - $(window).height())){

     alert('22')
}

这里的问题是,$(window).height() 返回的结果与 $(document).height() 相同,它比实际的窗口视口大。

我的屏幕结果约为 1280 像素。

但是 $(document).height 返回 1670,$(window).height() 也是如此。

所以 document.height - window.height 总是 0

难道我做错了什么?

我正在使用 Mac OSx Chrome。

谢谢

//////////////////////

window.innerHeight 和 document.height 解决了 Sushil 建议的问题

4

2 回答 2

1

这应该有效;

$(window).scroll(function()
{
    if($(window).scrollTop() == $(document).height() - $(window).height())
    {

    }
}); 
于 2012-10-14T22:02:07.850 回答
0

通过这个你可以得到如果你在一些 div 或 HTML 对象下面滚动

   $(window).scroll(function () {
    if($(window).scrollTop()+ $(window).height() >( $(".photo").offset().top +$(".photo").outerHeight()))
    {
    //YOUR CODE 
    }
  });
于 2014-01-11T09:58:55.617 回答