使用Masonry来做瀑布流加载, 但是在ajax中不能够完成,求方法.希望能够ajax中也能够使用imagesloaded来实现加载图片完成之后进行排列. - V2EX
justfindu

使用Masonry来做瀑布流加载, 但是在ajax中不能够完成,求方法.希望能够ajax中也能够使用imagesloaded来实现加载图片完成之后进行排列.

  •  
  •   justfindu Aug 23, 2013 8153 views
    This topic created in 4651 days ago, the information mentioned may be changed or developed.
    我的代码
    不会贴git代码 直接贴了

    html:

    <div class="container" id="wall">
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    ...
    </div>

    js:
    var cOntainer= jQuery('#wall');
    jQuery("#wall item").imagesLoaded(function(){
    container.masonry({
    gutter: 28,
    itemSelector: '.item',
    isAnimated: true
    });
    });

    ajax:

    jQuery.getJSON('http://localhost/test.json',function(data){
    var tmp;
    var l = data.length;
    var h = '';
    for(var i=0;i<l;i++){
    tmp =data[i];
    h += '<div class="item"><h5>'+tmp.title+'</h5><img src="'+tmp.image+'" alt=""></div>';
    }
    jQuery(h).imagesLoaded(function(){
    jQuery('#wall').append(jQuery(h)).masonry('appende', jQuery(h), true);
    });
    })


    在第一步加载js的时候是没有问题的,

    关键是触发ajax之后添加到后面的DOM就不会再瀑布流式的排列了.

    还有如果ajax改成如下

    jQuery.getJSON('http://localhost/test.json',function(data){
    var tmp;
    var l = data.length;
    var h = '';
    for(var i=0;i<l;i++){
    tmp =data[i];
    h = '<div class="item"><h5>'+tmp.title+'</h5><img src="'+tmp.image+'" alt=""></div>';
    jQuery(h).imagesLoaded(function(){
    jQuery('#wall').append(h).masonry('appended', jQuery(h), true);
    });
    }
    });

    这样的情况就是只会增加最后一个DOM, 而且前面的会空出来.

    求指教.

    尝试过 其他 masonry的reloaditems , 这个效果就是把新增加DOM的坐标全部清空.
    6 replies    1970-01-01 08:00:00 +08:00
    justfindu
        1
    justfindu  
    OP
       Aug 23, 2013
    是因为不贴git 所以没人看么- -
    dexbol
        2
    dexbol  
       Aug 23, 2013   1
    @justfindu 应该是。
    Gawie
        3
    Gawie  
       Aug 23, 2013   1
    没有配合infinitescroll 么
    justfindu
        4
    justfindu  
    OP
       Aug 26, 2013
    @Gawie 没尝试~ 我看过示例~ 我是绑定按钮~ 跟Masonry示例上的~ 我去搞搞
    ghbjy1128
        5
    ghbjy1128  
       Aug 26, 2013
    如果没有不需要考虑IE8的话,使用naturalHeight and naturalWidth最方便
    justfindu
        6
    justfindu  
    OP
       Aug 26, 2013
    @ghbjy1128 要是不考虑IE的话 这件事就变成简单多了~ 可是~ 哎~
    About     Help     Advertise     Blog     API     FAQ     Solana     2969 Online   Highest 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 38ms UTC 12:47 PVG 20:47 LAX 05:47 JFK 08:47
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86