2013-02-27 99 views
0

这是检测用户是否滚动到底部的代码。如何检测滚动到底部

$(window).scroll(function() { 
    var distance = $(window).scrollTop() -$(document).height() + $(window).height(); 
    console.log(distance); 
}); 

当我重新加载web浏览器(chrome),并且窗口滚动到底部时,chrome中的“距离”值为0或-1。 我不知道为什么会发生这种情况;

+0

http://stackoverflow.com/questions/9823645/detect-scroll-to-bottom-of-a-div?rq= 1 – 2013-02-27 05:34:09

回答

1

转换$(document).height()$(window).height()值如下面的整数值,

parseInt($(document).height()); 
parseInt($(window).height()); 
+0

谢谢你的回答。但结果相同。 – 2013-02-27 05:54:57

+0

@OhJongAm你的代码在chrome中工作...可能是jQuery版本有问题...我正在使用jQuery 1.9 – 2013-02-27 06:05:51

+0

我无法升级其他jquery插件的jQuery becasue。其他插件运行在jquery版本<= 1.8.3。所以目前我的jQuery版本是1.8.3 ... – 2013-02-27 06:29:39