Javascript 为什么$(document).scrollTop()不等于文档底部的$(document).height()?

Javascript 为什么$(document).scrollTop()不等于文档底部的$(document).height()?,javascript,jquery,html,css,Javascript,Jquery,Html,Css,我使用 var filled = ($(document).scrollTop() / $(document).height()); 我在文档底部得到0.8596615031325553而不是1,为什么会这样?? 我必须在我的代码中的其他地方动态地使用这个比率,但是因为它给出了意外的值,所以我不能使用它。我应该怎么做???$(文档)。scrollTop()返回当前视图的顶部距页面顶部的距离(即用户向下滚动的距离)$(document).height())返回整个页面的高度,从最上面的像素到最下

我使用

var filled = ($(document).scrollTop() / $(document).height());
我在文档底部得到0.8596615031325553而不是1,为什么会这样?? 我必须在我的代码中的其他地方动态地使用这个比率,但是因为它给出了意外的值,所以我不能使用它。我应该怎么做???

$(文档)。scrollTop()
返回当前视图的顶部距页面顶部的距离(即用户向下滚动的距离)
$(document).height())
返回整个页面的高度,从最上面的像素到最下面的像素

为了补偿这一点,您可以这样做:

var filled = (($(document).scrollTop() + $(window).height()) / $(document).height());

两者之间的区别应该是
window.innerHeight
。因此我需要将
window.innerHeight
添加到
$(document.scrollTop()
)以获得预期值??提琴:谢谢兄弟,它成功了!!!我在答案中添加了它。它也不起作用,它在文档底部给出了1.843853431717268,即使您复制了精确的行?
var filled=($(document.scrollTop()+window.innerHeight)/$(document.height())这个很好用。@ThomsoIitr好的,那就用这个吧。显然,它返回的值与jQuery的函数不同。