jQuery load more data on scroll

前端 未结 9 1050
夕颜
夕颜 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条回答
  •  萌比男神i
    2020-11-22 11:37

    If not all of your document scrolls, say, when you have a scrolling div within the document, then the above solutions won't work without adaptations. Here's how to check whether the div's scrollbar has hit the bottom:

    $('#someScrollingDiv').on('scroll', function() {
        let div = $(this).get(0);
        if(div.scrollTop + div.clientHeight >= div.scrollHeight) {
            // do the lazy loading here
        }
    });
    

提交回复
热议问题