Detecting when user scrolls to bottom of div with jQuery

前端 未结 15 1715
一个人的身影
一个人的身影 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:14

    $(window).on("scroll", function() {
        //get height of the (browser) window aka viewport
        var scrollHeight = $(document).height();
        // get height of the document 
        var scrollPosition = $(window).height() + $(window).scrollTop();
        if ((scrollHeight - scrollPosition) / scrollHeight === 0) {
            // code to run when scroll to bottom of the page
        }
    });
    

    This is the code on github.

提交回复
热议问题