I'm trying to use Masonryjs with imagesReveal "plugin" and with the width of the elements based on CSS (I need it because my items are sized with media queries).
This is my code:
$( function() {
var $container = $('#container').masonry({
itemSelector: '.item',
columnWidth: '.item'
});
var $items = $("#items .item");
$container.masonryImagesReveal( $items );
});
$.fn.masonryImagesReveal = function( $items ) {
var msnry = this.data('masonry');
var itemSelector = msnry.options.itemSelector;
// hide by default
$items.hide();
// append to container
this.append( $items );
$items.imagesLoaded().progress( function( imgLoad, image ) {
// get item
// image is imagesLoaded class, not <img>, <img> is image.img
var $item = $( image.img ).parents( itemSelector );
// un-hide item
$item.show();
// masonry does its thing
msnry.appended( $item );
});
return this;
};
Pen here:
http://codepen.io/FezVrasta/pen/yEilq
As you can see (check image) the items are not correctly placed, what am I doing wrong?