Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/73.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 图像在砌体中被附加了两次_Jquery_Plugins_Append_Jquery Masonry - Fatal编程技术网

Jquery 图像在砌体中被附加了两次

Jquery 图像在砌体中被附加了两次,jquery,plugins,append,jquery-masonry,Jquery,Plugins,Append,Jquery Masonry,我在砌石方面遇到了一个奇怪的问题。我使用的是无限滚动,当图像被加载时,它们会被附加两次。在添加更多页面后,我今天注意到了这个问题。我真的不确定是什么导致了它,但我想这与我的jQuery代码有关。我的代码如下 (function(){ //masonry $(function() { var container = document.querySelector('.post_container'); var msnry = new Masonry( container, {

我在砌石方面遇到了一个奇怪的问题。我使用的是无限滚动,当图像被加载时,它们会被附加两次。在添加更多页面后,我今天注意到了这个问题。我真的不确定是什么导致了它,但我想这与我的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');
        });
    });
(函数(){
//砌石
$(函数(){
var container=document.querySelector('.post_container');
var msnry=新砌体(容器、{
//选择权
项目选择器:'.post'
});
});
//加载的图像
var$container=$('.post_container');
$container.imagesLoaded(函数(){
$container.com({
项目选择器:'.post'
});
});
$('.container').infinitescroll({
导航选择器:“div.pagination”,
//分页导航的选择器(它将被隐藏)
下一个选择器:“#下一个a”,
//下一个链接的选择器(至第2页)
itemSelector:“.post”,
//将检索的所有项目的选择器
装载:{
完成:未定义,
finishedMsg:“祝贺你,你已经到达了互联网的尽头。”,
msg:null,
msgText:“正在加载下一组帖子…”,
选择器:null,
速度:“快”,
开始:未定义
}
},//回调以使所有组件一起工作
功能(新项目){
$container.append(newitems);
imagesLoaded(newitems,function(){
$container.mashise('附加',新项目);
$container.mashise(‘布局’);
});
});

我已经加倍检查了我的html,甚至删除了它,一次检查一张图片。出于某种原因,插件将图片附加两次。

这可能与此有关

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

我不熟悉砖石结构,但可能这就是为什么它会附加两次。

不,如果我没有,这是必要的,它会破坏功能。