A volte vi è la necessità che gli elementi di una griglia masonry abbiano tutti la stessa altezza. jQuery è molto utile in questo caso.
Possiamo definire il seguente plugin:
$.fn.equalCols = function() {
var sortNumber = function( a, b ) {
return b - a;
};
var heights = [];
$( this ).each(function(){
heights.push( $( this ).height() );
});
heights.sort( sortNumber );
var maxHeight = heights[0];
return this.each(function() {
$( this ).css( { height: maxHeight } );
});
};
Esempio d'uso:
$(function() {
$( ".masonry-item" ).equalCols();
});