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=0f&&(f=a)});a.css(e,f+"px")})}})(jQuery); \ No newline at end of file +(function(i){i.fn.equalize=function(e){var n,t,h=this,c=!1,s=!1,r=!1;return i.isPlainObject(e)?(n=e.equalize||"height",c=e.children||!1,s=e.reset||!1,r=e.group||!1):n=e||"height",i.isFunction(i.fn[n])?(t=n.indexOf("eight")>0?"height":"width",h.each(function(){for(var e=c?i(this).find(c):i(this).children(),h=r?Math.ceil(e.length/r):1,l=r?r:e.length,u=0,a=0;h>a;a++)u=0,e.slice(a*l,a*l+l).each(function(){var e,h=i(this);s&&h.css(t,""),e=h[n](),e>u&&(u=e)}),e.slice(a*l,a*l+l).css(t,u+"px")})):!1}})(jQuery); \ No newline at end of file