6

我想在元素滚动到视图时加载元素以减少服务器负载,例如缩略图,但希望它们的占位符divs在页面加载时就存在。div要做到这一点,我认为当它变得可见时我需要某种触发器。

建议使用 jquery-appear,但我似乎无法从任何地方获得它的副本(Google 给了我一个 403 错误)

有谁知道如何做到这一点?

4

1 回答 1

5

我认为 jQuery way points 是您可能需要的插件:

http://imakewebthings.com/jquery-waypoints/

以下是调用航点插件的方法:

$(document).ready(function() {
    var $loading = $("<div class='loading'><p>Loading more items&hellip;</p></div>"),
    $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);
});
于 2012-11-28T07:44:50.857 回答