jQuery load more data on scroll

前端 未结 9 1048
夕颜
夕颜 2020-11-22 10:44

I am just wondering how can i implement more data on scroll only if the div.loading is visible.

Usually we look for page height and scroll height, to see if we need

9条回答
  •  没有蜡笔的小新
    2020-11-22 11:39

    Improving on @deepakssn answer. There is a possibility that you want the data to load a bit before we actually scroll to the bottom.

    var scrollLoad = true;
    $(window).scroll(function(){
     if (scrollLoad && ($(document).height() - $(window).height())-$(window).scrollTop()<=800){
        // fetch data when we are 800px above the document end
        scrollLoad = false;
       }
      });
    

    [var scrollLoad] is used to block the call until one new data is appended.

    Hope this helps.

提交回复
热议问题