JSFiddle - React, Tailwind, and code Playground
HTML
<div id="mosaicWrapper">
<div class="mosaic">a</div>
<div class="mosaic">b</div>
<div class="mosaic">c</div>
<div class="mosaic">d</div>
<div class="mosaic">e</div>
<div class="mosaic">f</div>
<div class="mosaic">g</div>
<div class="mosaic">h</div>
<div class="mosaic">i</div>
<div class="mosaic">j</div>
<div class="mosaic">k</div>
<div class="mosaic">l</div>
<div class="mosaic">m</div>
<div class="clear"></div>
</div>
CSS
*{margin:0; padding:0}
body{ width:100%; height:100%}
.clear{clear:both; float:none}
#mosaicWrapper{ width:70%; background:#ccc}
.mosaic{ width:20%; background:#06C; height:150px; float:left; margin:20px 20px 0 0; color:white; text-align:center; font-size:74px; position:relative; cursor:pointer}
JavaScript
(function($){
$.fn.margin = function(direction) {
var intPart = this.css('margin-' + direction).replace(/[^-\d\.]/g, '');
return intPart;
};
})(jQuery);
var MSC = MSC || {};
MSC.init = function(){
var wrapper = $('#mosaicWrapper');
var mosaic = $('.mosaic');
var mosaicWidth = mosaic.outerWidth(true);
var elesPerRow= Math.floor(wrapper.width()/mosaicWidth);
var expandedWidth = (mosaicWidth*(elesPerRow-1))-mosaic.margin('right');
var lastItems = [];
var intialWidth = mosaic.width();
for (var i = elesPerRow; i < mosaic.length; i = i + elesPerRow){
var lItem = i - 1;
lastItems.push(lItem);
}
mosaic.each(function(index, element) {
thisItem = $(this);
thisItem.mouseover(function(e) {
$(this).stop(false, false).animate({'width':expandedWidth},500);
if($.inArray(index, lastItems) > -1){
var last = index - 1;
};
});
thisItem.mouseleave(function(e) {
$(this).stop(false, false).animate({'width':intialWidth},500);
});
});
}
$(document).ready(function(e) {
MSC.init();
});