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>

By setting clear to true the height/width will be removed.
<pre>$('.parent').equalize({clear: true}); // default to clear height
$('.parent').equalize({equalize: 'width', clear: true}); // clear width</pre>

## Examples

Expand Down
5 changes: 3 additions & 2 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ td { vertical-align: top; }


/* =========================================================================
Primary Styles
Primary Styles
========================================================================== */

body { color: #333; padding-bottom: 3em; }
Expand Down Expand Up @@ -138,6 +138,7 @@ pre {
}

#advanced-example div,
#clear-example div,
#height-example div { width: 60px; }
/* #width-example div { } */

Expand Down Expand Up @@ -174,7 +175,7 @@ pre {
/* =============================================================================
Print Styles
========================================================================== * /

@media print {
* { background: transparent !important; color: black !important; box-shadow:none !important; text-shadow: none !important; filter:none !important; -ms-filter: none !important; } /* Black prints faster: h5bp.com/s * /
a, a:visited { text-decoration: underline; }
Expand Down
25 changes: 24 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ <h2>Advanced Usage</h2>
<p>Equalize the .parent's child element. See @larsbo's <a href="http://jsfiddle.net/4QTNP/3/">example</a>.</p>
<pre>$('.parent').equalize({children: 'p'}); // equalize height of paragraphs within .parent</pre>

<p>By setting clear to true the height/width will be removed.</p>
<pre>$('.parent').equalize({clear: true}); // default to clear height
$('.parent').equalize({equalize: 'width', clear: true}); // clear width</pre>

<h2>Height Example <a id="run-height" href="#height-example">run »</a></h2>
<pre>$('#height-example').equalize(); // defaults to height</pre>

Expand Down Expand Up @@ -75,7 +79,7 @@ <h2>Width Example <a id="run-width" href="#width-example">run »</a></h2>


<h2>Advanced Example <a id="run-advanced" href="#advanced-example">run »</a></h2>
<pre>$('#height-example').equalize({reset: true});</pre>
<pre>$('#advanced-example').equalize({reset: true});</pre>
<p>Below the tallest div has a height of 200px, this will be removed before determining the max height, otherwise all elements would have a height of 200px.</p>

<div id="advanced-example" class="example">
Expand All @@ -90,6 +94,23 @@ <h2>Advanced Example <a id="run-advanced" href="#advanced-example">run »</a></h
<div>equalize content height</div>
<div>equalize</div>
</div>

<h2>Clear Example <a id="run-clear" href="#clear-example">run »</a></h2>
<pre>$('#clear-example').equalize({reset: true});</pre>
<p>Below the tallest div has a height of 200px, this will be cleared.</p>

<div id="clear-example" class="example">
<div>equalize</div>
<div>equalize content height</div>
<div style="height:200px;">equalize</div>
<div>equalize</div>
<div>equalize</div>
<div>equalize content</div>
<div>equalize</div>
<div>equalize</div>
<div>equalize content height</div>
<div>equalize</div>
</div>
</div>


Expand All @@ -105,6 +126,8 @@ <h2>Advanced Example <a id="run-advanced" href="#advanced-example">run »</a></h
if (this.id === 'run-advanced') {
// reset all the heights to get the minimum max height
$('#advanced-example').equalize({reset: true});
} else if (this.id === 'run-clear') {
$('#clear-example').equalize({clear: true}); // defaults to height
} else if (this.id === 'run-height') {
$('#height-example').equalize(); // defaults to height
} else {
Expand Down
10 changes: 8 additions & 2 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,
clear = false,
equalize,
type;

Expand All @@ -39,6 +40,7 @@
equalize = options.equalize || 'height';
children = options.children || false;
reset = options.reset || false;
clear = options.clear || false;
} else { // otherwise, a string was passed in or default to height
equalize = options || 'height';
}
Expand All @@ -56,12 +58,16 @@
$children.each(function() {
var $element = $(this),
value;
if (reset) { $element.css(type, ''); } // remove existing height/width dimension
if (reset || destroy) { $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
if (destroy) {
$children.css(type, ''); // remove CSS from children
} else {
$children.css(type, max +'px'); // add CSS to children
} // destroy function
});
};

Expand Down
2 changes: 1 addition & 1 deletion js/equalize.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* Page: http://tsvensen.github.com/equalize.js
* Repo: https://github.com/tsvensen/equalize.js/
*/
!function(i){i.fn.equalize=function(e){var n,t,h=!1,c=!1;return i.isPlainObject(e)?(n=e.equalize||"height",h=e.children||!1,c=e.reset||!1):n=e||"height",i.isFunction(i.fn[n])?(t=0<n.indexOf("eight")?"height":"width",this.each(function(){var e=h?i(this).find(h):i(this).children(),s=0;e.each(function(){var e=i(this);c&&e.css(t,""),e=e[n](),e>s&&(s=e)}),e.css(t,s+"px")})):!1}}(jQuery);
!function(a){a.fn.equalize=function(b){var g,h,c=this,d=!1,e=!1,f=!1;return a.isPlainObject(b)?(g=b.equalize||"height",d=b.children||!1,e=b.reset||!1,f=b.clear||!1):g=b||"height",!!a.isFunction(a.fn[g])&&(h=g.indexOf("eight")>0?"height":"width",c.each(function(){var b=d?a(this).find(d):a(this).children(),c=0;b.each(function(){var d,b=a(this);(e||destroy)&&b.css(h,""),d=b[g](),d>c&&(c=d)}),destroy?b.css(h,""):b.css(h,c+"px")}))}}(jQuery);