Created
January 23, 2012 02:16
-
-
Save ryanfitzer/1660062 to your computer and use it in GitHub Desktop.
Optimized `equalHeights()`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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