Created
May 1, 2017 22:37
-
-
Save michaelchadwick/5d98525a1a78ca8646f7be27d2fa1a4d to your computer and use it in GitHub Desktop.
Dynamically resize elements based on tallest one
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
// dynamically size elements based on tallest one | |
equalheight = function(container) { | |
var currentTallest = 0, | |
currentRowStart = 0, | |
rowDivs = new Array(), | |
$el, | |
topPostion = 0; | |
$(container).each(function() { | |
$el = $(this); | |
$($el).height('auto'); | |
topPosition = $el.position().top; | |
if (currentRowStart != topPosition) { | |
for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) { | |
rowDivs[currentDiv].height(currentTallest); | |
} | |
rowDivs.length = 0; currentRowStart = topPosition; | |
currentTallest = $el.height(); | |
rowDivs.push($el); | |
} else { | |
rowDivs.push($el); | |
currentTallest = (currentTallest < $el.height()) ? ($el.height()) : (currentTallest); | |
} | |
for (currentDiv = 0; currentDiv < rowDivs.length; currentDiv++) { | |
rowDivs[currentDiv].height(currentTallest); | |
} | |
}); | |
} | |
$(window).on('load resize', function() { | |
equalheight(elementName); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment