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

后端 未结 8 734
难免孤独
难免孤独 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:39

    In order to get the correct results when taking into account things such as the possibility of a border, horizontal scrollbar, and/or floating pixel count, you should use...

    el.scrollHeight - el.scrollTop - el.clientHeight < 1
    

    NOTE: You MUST use clientHeight instead of offsetHeight if you want to get the correct results. offsetHeight will give you correct results only when el doesn't have a border or horizontal scrollbar

提交回复
热议问题