确定何时使用 Javascript 滚动到页面底部 [英] Determining when scrolled to bottom of a page with Javascript
问题描述
我正在尝试确定何时滚动到页面底部(不使用任何 JS 库),但到目前为止,我对使用以下哪一个感到有些困惑.我见过的最有希望的是 window.scrollY
,但即使滚动到页面底部,它也永远不会匹配 window.innerHeight
的值.这样做的最佳方法是什么?
window.innerWidthwindow.innerHeightwindow.outerWidthwindow.outerHeight窗口.scrollX窗口.scrollYdocument.body.scrollWidthdocument.body.scrollHeightdocument.body.scrollTopdocument.body.scrollLeftdocument.body.offsetTopdocument.body.offsetLeftdocument.body.offsetWidthdocument.body.offsetHeight
when window.innerHeight
+ document.body.scrollTop
大于等于 document.body.offsetHeight
那么你在底部
但是由于 IE 对这些属性有问题,您需要使用替代属性,例如
document.documentElement.scrollTop
用于滚动,document.documentElement.clientHeight
用于窗口高度
完整代码:http://jsbin.com/egegu3/6/edit>
I'm trying to determine when I've scrolled to the bottom of the page (without using any JS library), but so far, I'm a bit confused over which one of the following to use. The most promising one I've seen is window.scrollY
, but even when scrolled to the bottom of the page, it never matches the value of window.innerHeight
. What's the best way to do this?
window.innerWidth
window.innerHeight
window.outerWidth
window.outerHeight
window.scrollX
window.scrollY
document.body.scrollWidth
document.body.scrollHeight
document.body.scrollTop
document.body.scrollLeft
document.body.offsetTop
document.body.offsetLeft
document.body.offsetWidth
document.body.offsetHeight
when window.innerHeight
+ document.body.scrollTop
is greater than or equal to document.body.offsetHeight
then you are at bottom
but since IE has issues with these properties you need to use alternative properties, like
document.documentElement.scrollTop
for the scroll and document.documentElement.clientHeight
for the window height
full code: http://jsbin.com/egegu3/6/edit
这篇关于确定何时使用 Javascript 滚动到页面底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!