scrollTop()在firefox和chrome中有所不同

scrollTop() different in firefox vs chrome

本文关键字:chrome 有所不同 firefox scrollTop      更新时间:2024-05-08

我想要窗口的整个可滚动高度。然而,chrome在不滚动的情况下返回用户可见部分的长度,而firefox则返回整个可滚动长度。如何在不首先检测浏览器的情况下修复这种不一致性。目前我正在使用

$(window).scrollTop()

$(window).scrollTop()在两者中的工作原理相同,它"告诉"您向下滚动了多远。

$(window).height()给出视口的高度。

$(document).height()给出了我认为您正在寻找的文档的高度。

或者,如果您只在视口外查找滚动高度,则

$(document).height() - $(window).height()