Skip to content

Instantly share code, notes, and snippets.

@Origame
Created July 8, 2016 07:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Origame/e493052eac59786d57cd7c7a8f057190 to your computer and use it in GitHub Desktop.
Save Origame/e493052eac59786d57cd7c7a8f057190 to your computer and use it in GitHub Desktop.
JS - function to set the same height of items on a row
/* Set boxes height to match the highest box on the same row */
setBoxHeight: function(){
var boxes = $j('.myBoxes', this.$scope); //Selector and scope
var boxesByRow = 3; //Nb of items on a row
//Create each row
for(var i = 0; i < boxes.length; i+=boxesByRow) {
var newRow = boxes.slice(i, i+boxesByRow);
setHeight(newRow);
}
//Apply the highest "auto" box height to all the boxes of the row
function setHeight(row){
var autoHighest = 0;
row.each(function(){
var autoHeight = $j(this).css('height', 'auto').outerHeight();
if ( autoHeight > autoHighest ){
autoHighest = autoHeight;
}
});
var newHeight = autoHighest;
row.height(newHeight);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment