Created
March 3, 2014 08:44
-
-
Save ariera/9320870 to your computer and use it in GitHub Desktop.
adjustHeights
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
adjustHeights: (target) -> | |
#http://css-tricks.com/equal-height-blocks-in-rows/ | |
currentTallest = 0 | |
currentRowStart = 0 | |
rowDivs = new Array() | |
topPosition = 0 | |
target.each -> | |
$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) | |
rowDiv.height(currentTallest) for rowDiv in rowDivs | |
# 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 = Math.max(currentTallest, $el.height()) | |
# do the last row | |
rowDiv.height(currentTallest) for rowDiv in rowDivs |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment