Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ This advanced usage is for dynamic instances where equalize is ran after element
Equalize the .parent's child element. See @larsbo's <a href="http://jsfiddle.net/4QTNP/3/">example</a>.
<pre>$('.parent').equalize({children: 'p'}); // equalize height of paragraphs within .parent</pre>

You can even evaluate your children in groups:
<pre>$('.parent').equalize({children: 'p', group: 3}); // equalize height of paragraphs in groups of 3 elements within .parent</pre>


## Examples

Expand Down
23 changes: 15 additions & 8 deletions js/equalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
var $containers = this, // this is the jQuery object
children = false,
reset = false,
group = false,
equalize,
type;

Expand All @@ -39,6 +40,7 @@
equalize = options.equalize || 'height';
children = options.children || false;
reset = options.reset || false;
group = options.group || false;
} else { // otherwise, a string was passed in or default to height
equalize = options || 'height';
}
Expand All @@ -51,17 +53,22 @@
return $containers.each(function() {
// when children exist, equalize the passed in child elements, otherwise equalize the children
var $children = (children) ? $(this).find(children) : $(this).children(),
iterations = (group) ? Math.ceil($children.length / group) : 1,
groupSize = (group) ? group : $children.length,
max = 0; // reset for each container

$children.each(function() {
var $element = $(this),
value;
if (reset) { $element.css(type, ''); } // remove existing height/width dimension
value = $element[equalize](); // call height(), outerHeight(), etc.
if (value > max) { max = value; } // update max
});
for (var i = 0; i < iterations; i++) {
max = 0;
$children.slice(i * groupSize, (i * groupSize) + groupSize).each(function() {
var $element = $(this),
value;
if (reset) { $element.css(type, ''); } // remove existing height/width dimension
value = $element[equalize](); // call height(), outerHeight(), etc.
if (value > max) { max = value; } // update max
});

$children.css(type, max +'px'); // add CSS to children
$children.slice(i * groupSize, (i * groupSize) + groupSize).css(type, max +'px'); // add CSS to children
}
});
};

Expand Down
10 changes: 1 addition & 9 deletions js/equalize.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.