如何判断div是否滚动到底部? [英] How can I determine if a div is scrolled to the bottom?
问题描述
如果不使用jQuery或任何其他JavaScript库,如果将带有垂直滚动条的div一直滚动到底部,如何确定?
How do I determine, without using jQuery or any other JavaScript library, if a div with a vertical scrollbar is scrolled all the way to the bottom?
我的问题不是如何滚动到底部。我知道该怎么做。我想确定div是否已经滚动到底部。
My question is not how to scroll to the bottom. I know how to do that. I want to determine if the the div is scrolled to the bottom already.
这不起作用:
if (objDiv.scrollTop == objDiv.scrollHeight)
推荐答案
你很接近 scrollTop == scrollHeight
。
scrollTop
指的是滚动位置的顶部,它将是 scrollHeight - offsetHeight
scrollTop
refers to the top of the scroll position, which will be scrollHeight - offsetHeight
你的if语句应如此(不要忘记使用三等于):
Your if statement should look like so (don't forget to use triple equals):
if( obj.scrollTop === (obj.scrollHeight - obj.offsetHeight))
{
}
编辑:更正了我的回答,完全错了
Corrected my answer, was completely wrong
这篇关于如何判断div是否滚动到底部?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!