I’m runnig RoR application with a wall of blocks using Vanilla Masonry, and each block in this wall could be flipped with JQuery Flip! plugin. The issue is that the length of contents on each side of the block could be different, so I want the wall positions reloading after each flip action, to avoid overlapping.
My code works one-way, when I flip the block for the first-time, but when I revert flipping, I encounter overlapping.
I initialize Masonry on load and here is my code for flipping-wall.js:
$(document).ready(function(){
$('.sponsorFlip').bind("click",function(){
var elem = $(this);
var wall = new Masonry( document.getElementById('container'), {
gutterWidth:5,
isFitWidth: true
});
if(elem.data('flipped'))
{
elem.revertFlip();
elem.data('flipped',false);
wall.reload();
}
else
{
elem.flip({
direction:'lr',
speed: 350,
onBefore: function(){
elem.html(elem.siblings('.sponsorData').html());
}
});
elem.data('flipped',true);
wall.reload();
}
});
});
Here is three steps:



Please, can you tell me what am I doing wrong.
Thanks guys.
As far as I can tell (tested on my localhost), after flipping is done you have to refer to already initialized Masonry object (instead of creating yet another instance) and reload it.
It could loook like this (put that in place of your onload function).
P.S.
Using jQuery Masonry would save you some hassle as it can be embedded in head.