2012-03-28 63 views
4

类似于描述的问题here,在某些情况下,$(window).scrollTop()将在Firefox中关闭一个。scrollTop off by 1 pixel in Firefox

我用这个来检测,如果垂直滚动条已经到达底部:

if ($(window).scrollTop() == $(document).height() - $(window).height()) 
{ 
    // bottom reached 
} 

这工作。但我只是偶然发现,它只适用于大部分时间。以下是出错情况下的日志。 scrollTop说我滚动611像素,difference是说我能够滚动612像素。

scrollTop: 611 
doc height: 933 
win height: 321 
difference: 612 

代码有问题吗?或者这是一个Firefox的问题?在后一种情况下,我想我可以改变它来检查它是否剩余5个或更少的像素。但是如果代码错了,我想解决它。下面的代码

+0

你就不能写:'如果($(窗口).scrollTop()> = $(文件).height() - $(窗口).height ()){...}'? – meeDamian 2012-04-25 18:10:05

+0

@ chester1000不,因为如果你看看这些值,'scrollTop' <''差异'。 – Stijn 2012-04-26 07:47:42

+2

只是一个想法,这可能是由亚像素渲染引起的。 http://blogs.msdn.com/b/ie/archive/2012/02/17/sub-pixel-rendering-and-the-css-object-model.aspx?Redirected=true – 2012-05-13 23:31:02

回答

1

使用它的工作原理

if ($(window).scrollTop() >= ($(document).height() - $(window).height()-1)) 
+0

感谢您的回答,虽然这是一个类似于问题中描述的解决方法。 – Stijn 2012-06-28 09:16:34