JQuery Detect Scroll at Bottom

后端 未结 10 742
南方客
南方客 2021-01-30 09:58

I wish to achieve content load when the user scrolls to the bottom of the page.

I am having a problem. It works fine on desktop browsers but not on mobile. I have imple

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-30 10:16

    Using jquery and Strelok's getDocumentHeight() below (cheers!) I found the following worked pretty well. Testing for equality didn't work for me as the iPhone only registered a scroll value at the end of the slide which was actually greater than the document height:

    $(window).scroll(function () {
      var docHeight = getDocumentHeight();         
      if ($(window).scrollTop() + $(window).height() >= docHeight) {
        // Do stuff
      }
    });
    

提交回复
热议问题