如何确定 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屋!