Created
July 18, 2014 14:49
-
-
Save ElmahdiMahmoud/2bda5d8a0ee007d501f8 to your computer and use it in GitHub Desktop.
equal height cols
This file contains 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
/* [ equal height cols ] */ | |
var currentTallest = 0, | |
currentRowStart = 0, | |
rowDivs = new Array(), | |
$el, | |
topPosition = 0; | |
$('.eq-height').each(function() { | |
$el = $(this); | |
topPostion = $el.position().top; | |
if (currentRowStart != topPostion) { | |
// we just came to a new row. Set all the heights on the completed row | |
for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) { | |
rowDivs[currentDiv].height(currentTallest); | |
} | |
// set the variables for the new row | |
rowDivs.length = 0; // empty the array | |
currentRowStart = topPostion; | |
currentTallest = $el.height(); | |
rowDivs.push($el); | |
} else { | |
// another div on the current row. Add it to the list and check if it's taller | |
rowDivs.push($el); | |
currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest); | |
} | |
// do the last row | |
for (currentDiv = 0 ; currentDiv < rowDivs.length ; currentDiv++) { | |
rowDivs[currentDiv].height(currentTallest); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment