jQuery: detecting reaching bottom of scroll doesn't work, only detects the top

后端 未结 8 780
梦毁少年i
梦毁少年i 2020-12-01 11:44

So basically my problem is a seemingly simple one.

You can see it in action at http://furnace.howcode.com (please note that data is returned via Ajax, so if nothing

8条回答
  •  自闭症患者
    2020-12-01 11:58

    I know this question is already solved, but a concern when using jQuery scrollTOp() function on element other than on $(window).scrollTop() or $(document).scrollTop() since some issue like

    jQuery: detecting reaching bottom of scroll doesn't work, only detects the top

    Explain why scrollTop() always returns 0 here

    $(document).scrollTop() always returns 0

    So you can use

    $(window).scrollTop() - $('your_selector').offset().top 
    

    instead of

    $('your_selector').scrollTOp() 
    

    to avoid the jQuery scrollTOp() issue.

    My suggestion is as follows:

       $(window).scroll(function() {
           var $more = $('#col2');
           var top = $(window).scrollTop() - $more.offset().top;
           if(top + $more.innerHeight() >= $more[0].scrollHeight) {
              loadMore();
           }
       });
    

提交回复
热议问题