jQuery masonry with Wordpress and imagesLoaded

南楼画角 提交于 2019-12-04 16:05:08

I think this should work for you;

// Masonry Trigger
var $container = jQuery('#masonry-wrap');

$container.imagesLoaded( function(){
   $container.masonry({ 
     itemSelector: '.masonry-box', 
     columnWidth: 283 
   }); 
})

Remember to use the latest version of imagesLoaded, I had a problem a while back and the reason was my version was slightly out of date.

EDIT

That said, I only use imagesLoaded when I've loaded in new content via AJAX and am using the reLayout method. If you run masonry on $window.load() after the images are loaded it should run fine too.

(function($){

    $(window).load(function() {

      // Masonry Trigger
      var $container = $('#masonry-wrap');

      $container.masonry({
         // options
         itemSelector: '.masonry-box', 
         columnWidth: 283 
      });

    }); 

})(jQuery);         
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!