Skip to content

Instantly share code, notes, and snippets.

@felixzapata
Created July 19, 2013 09:16
Show Gist options
  • Save felixzapata/6037845 to your computer and use it in GitHub Desktop.
Save felixzapata/6037845 to your computer and use it in GitHub Desktop.
Igualador de alturas de elementos parametrizado
var setEqualHeight = function(){
"use strict";
function init(){
var obj = $(".setEqualHeight");
obj.each(function(){
var $that = $(this),
itemToSetHeight = $that.attr('data-itemToSetHeight'),
elementsToCompare = $that.attr('data-elementsToCompare');
calculateHeight($that, itemToSetHeight, elementsToCompare);
});
}
function calculateHeight(container, itemToSetHeight, elementsToCompare){
var elemens = container.find("."+itemToSetHeight),
len = elemens.length,
i, heights, finalHeight, rowOfItems;
for(i = 0; i < len; i+=elementsToCompare) {
rowOfItems = elemens.slice(i, i+elementsToCompare);
heights = getHeights(rowOfItems);
finalHeight = Math.max.apply(Math, heights);
setFinalHeight(finalHeight, rowOfItems);
}
}
function setFinalHeight(height, items){
items.css('min-height', height);
}
function getHeights(items){
var heights = [], i,
len = items.length;
for (i = 0; i < len; i++){
heights.push(items.eq(i).height());
}
return heights;
}
return {
init:init
};
}();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment