jQuery Masonry and Ajax Append Items?

前端 未结 13 1398
借酒劲吻你
借酒劲吻你 2020-12-08 07:19

I am trying to use some ajax and the jQuery Masonry plugin to add some items - but for some reason the new items aren\'t getting the masonry applied ?

I\'m using

13条回答
  •  一向
    一向 (楼主)
    2020-12-08 07:51

    I added the following code after the append command and everything was fine:

    $grid.imagesLoaded().progress( function() {
        $grid.masonry('layout');
    });
    

    The reason:

    Unloaded images can throw off Masonry layouts and cause item elements to overlap. imagesLoaded resolves this issue. imagesLoaded is a separate script you can download at imagesloaded.desandro.com.

    source

提交回复
热议问题