So here is what I am trying to do. I have a grid with a lot of images, so I use the imagesLoaded library along with the masonry.
Here is my CSS:
.grid { opacity:0; }
And HTML:
<div class="grid"> <div class="grid-sizer"></div> <div class="gutter-sizer"></div> <div class="item">image</div> <div class="item">image</div> <div class="item">image</div> </div>
And here is my JS:
var $container = $('.grid'); // initialize Masonry after all images have loaded $container.imagesLoaded( function() { $container.masonry({ columnWidth: '.grid-sizer', itemSelector: '.item', gutter: '.gutter-sizer' }); $container.masonry('on', 'layoutComplete', function(){ console.log('got here'); $container.animate({'opacity':1}); }); });
My goal is to hide the grid until all the images are loaded and the layout is complete and then disappears. For some reason, in my code above, it never ends up in a layoutComplete block.
If I moved this block beyond imagesLoaded, $ container.masonry will be undefined by this point.
Any ideas?
FIDDLE HERE
If you change the opacity of the grid to 1, you will see that everything turns out elegantly. Just trying to figure out how to get layoutComplete for the call to set the opacity to 1.
Corey source share