Skip to content

Instantly share code, notes, and snippets.

@ariera
Created March 3, 2014 08:44
Show Gist options
  • Save ariera/9320870 to your computer and use it in GitHub Desktop.
Save ariera/9320870 to your computer and use it in GitHub Desktop.
adjustHeights
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