jQuery load more data on scroll

前端 未结 9 1087
夕颜
夕颜 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:46

    Have you heard about the jQuery Waypoint plugin.

    Below is the simple way of calling a waypoints plugin and having the page load more Content once you reaches the bottom on scroll :

    $(document).ready(function() {
        var $loading = $("

    Loading more items…

    "), $footer = $('footer'), opts = { offset: '100%' }; $footer.waypoint(function(event, direction) { $footer.waypoint('remove'); $('body').append($loading); $.get($('.more a').attr('href'), function(data) { var $data = $(data); $('#container').append($data.find('.article')); $loading.detach(); $('.more').replaceWith($data.find('.more')); $footer.waypoint(opts); }); }, opts); });

提交回复
热议问题