Skip to content

Instantly share code, notes, and snippets.

@michaelchadwick
Created May 1, 2017 22:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaelchadwick/5d98525a1a78ca8646f7be27d2fa1a4d to your computer and use it in GitHub Desktop.
Save michaelchadwick/5d98525a1a78ca8646f7be27d2fa1a4d to your computer and use it in GitHub Desktop.
Dynamically resize elements based on tallest one
// 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