How can I determine if a div is scrolled to the bottom?

后端 未结 8 745
难免孤独
难免孤独 2020-12-12 20:18

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?

My question is no

8条回答
  •  一个人的身影
    2020-12-12 20:32

    You're pretty close using scrollTop == scrollHeight.

    scrollTop refers to the top of the scroll position, which will be scrollHeight - offsetHeight

    Your if statement should look like so (don't forget to use triple equals):

    if( obj.scrollTop === (obj.scrollHeight - obj.offsetHeight))
    {
    }
    

    Edit: Corrected my answer, was completely wrong

提交回复
热议问题