Created
July 8, 2016 07:32
-
-
Save Origame/e493052eac59786d57cd7c7a8f057190 to your computer and use it in GitHub Desktop.
JS - function to set the same height of items on a row
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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