diff --git a/README.md b/README.md index 03f886d..f2243ba 100644 --- a/README.md +++ b/README.md @@ -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 example.
$('.parent').equalize({children: 'p'}); // equalize height of paragraphs within .parent
+You can even evaluate your children in groups:
+$('.parent').equalize({children: 'p', group: 3}); // equalize height of paragraphs in groups of 3 elements within .parent
+
## Examples
diff --git a/js/equalize.js b/js/equalize.js
index 1939680..49107e6 100644
--- a/js/equalize.js
+++ b/js/equalize.js
@@ -31,6 +31,7 @@
var $containers = this, // this is the jQuery object
children = false,
reset = false,
+ group = false,
equalize,
type;
@@ -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';
}
@@ -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
+ }
});
};
diff --git a/js/equalize.min.js b/js/equalize.min.js
index e5df45d..a4970bc 100644
--- a/js/equalize.min.js
+++ b/js/equalize.min.js
@@ -1,9 +1 @@
-/**
- * equalize.js
- * Author & copyright (c) 2012: Tim Svensen
- * Dual MIT & GPL license
- *
- * Page: http://tsvensen.github.com/equalize.js
- * Repo: https://github.com/tsvensen/equalize.js/
- */
-(function(b){b.fn.equalize=function(a){var d=!1,g=!1,c,e;b.isPlainObject(a)?(c=a.equalize||"height",d=a.children||!1,g=a.reset||!1):c=a||"height";if(!b.isFunction(b.fn[c]))return!1;e=0