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

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

    Little late to this party, but none of the above answers seem to work particularly well when...

    • Display scaling is applied to the OS for UHD displays
    • Scaling/zoom is applied to the browser

    To accommodate for all eventualities, you will need to round up the calculated scroll position:

    Math.ceil(element.scrollHeight - element.scrollTop) === element.clientHeight
    

提交回复
热议问题