Detecting when user scrolls to bottom of div with jQuery

前端 未结 15 1861
一个人的身影
一个人的身影 2020-11-22 14:47

I have a div box (called flux) with a variable amount of content inside. This divbox has overflow set to auto.

Now, what I am trying to do, is, when the use scroll t

15条回答
  •  日久生厌
    2020-11-22 15:32

    If you need to use this on a div that has overflow-y as hidden or scroll, something like this may be what you need.

    if ($('#element').prop('scrollHeight') - $('#element').scrollTop() <= Math.ceil($('#element').height())) {
        at_bottom = true;
    }
    

    I found ceil was needed because prop scrollHeight seems to round, or perhaps some other reason causing this to be off by less than 1.

提交回复
热议问题