【问题标题】:Images are being appended twice in Masonry图像在 Masonry 中被附加了两次
【发布时间】:2014-06-10 11:33:26
【问题描述】:

我在砌体方面遇到了一个奇怪的问题。我正在使用无限滚动,当加载图像时,它们会被附加两次。添加更多页面后,我今天注意到了这个问题。我真的不确定是什么原因造成的,但认为它与我的 jQuery 代码有关。我的代码如下。

(function(){

//masonry
$(function() {
    var container = document.querySelector('.post_container');
    var msnry = new Masonry( container, {
        // options
        itemSelector: '.post'
    });
});

//images loaded
var $container = $('.post_container');
$container.imagesLoaded(function(){
    $container.masonry({
        itemSelector : '.post'

    });
});

$('.container').infinitescroll({
        navSelector  : "div.pagination",
        // selector for the paged navigation (it will be hidden)
        nextSelector : "#next a",
        // selector for the NEXT link (to page 2)
        itemSelector : '.post',
        // selector for all items you'll retrieve

        loading: {
            finished: undefined,
            finishedMsg: "<em>Congratulations, you've reached the end of the internet.</em>",
            msg: null,
            msgText: "<em>Loading the next set of posts...</em>",
            selector: null,
            speed: 'fast',
            start: undefined
        }
    }, //callback to make the all work together
    function(newitems) {
        $container.append(newitems);
        imagesLoaded(newitems, function(){
            $container.masonry('appended', newitems);
            $container.masonry('layout');
        });
    });

我已经仔细检查了我的 html,甚至将其删除并一次检查每个图像。由于某种原因,插件将图像附加了两次。

【问题讨论】:

    标签: jquery plugins append jquery-masonry


    【解决方案1】:

    可能跟这个有关

    function(newitems) {
        $container.append(newitems);  // appending the same thing
        imagesLoaded(newitems, function(){
            $container.masonry('appended', newitems); // appending the same thing
            $container.masonry('layout');
        });
    });
    

    我对砌体不熟悉,但也许这就是它要附加两次的原因。

    【讨论】:

    • 不,如果我没有它会破坏功能。
    猜你喜欢
    • 1970-01-01
    • 2020-12-31
    • 1970-01-01
    • 2017-06-25
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多