Skip to content

Instantly share code, notes, and snippets.

@ryanfitzer
Created January 23, 2012 02:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanfitzer/1660062 to your computer and use it in GitHub Desktop.
Save ryanfitzer/1660062 to your computer and use it in GitHub Desktop.
Optimized `equalHeights()`
$.fn.equalHeights = function( px ) {
$( this ).each( function() {
var currentElement,
currentHeight,
currentTallest = 0,
children = $( this ).children();
children.each( function() {
currentElement = $( this );
currentHeight = currentElement.height();
if ( currentHeight > currentTallest ) currentTallest = currentHeight;
});
if ( !px || !Number.prototype.pxToEm ) currentTallest = currentTallest.pxToEm(); //use ems unless px is specified
// for ie6, set height since min-height isn't supported
if ( $.browser.msie && $.browser.version == 6.0 ) {
children.css({
'height': currentTallest
});
} else {
children.css({
'min-height': currentTallest
});
}
});
return this;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment