Skip to content

Instantly share code, notes, and snippets.

@k7y6t5
Last active August 29, 2015 14:06
Show Gist options
  • Save k7y6t5/34bfefd7344b6dbdda76 to your computer and use it in GitHub Desktop.
Save k7y6t5/34bfefd7344b6dbdda76 to your computer and use it in GitHub Desktop.
Equal height columns
/*-----------------------
@EQUAL HEIGHT BLOCKS
http://css-tricks.com/equal-height-blocks-in-rows/
------------------------*/
namespace.equal_height = (function(){
var settings = {
$targets: $(".equal-height-columns"),
};
return {
init: function() {
var currentTallest = 0,
currentRowStart = 0,
rowDivs = [],
$el,
topPosition = 0;
settings.$targets.each(function() {
$el = $(this);
topPostion = $el.position().top;
if (currentRowStart != topPostion) {
// 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