Created
November 1, 2010 16:56
-
-
Save preaction/658491 to your computer and use it in GitHub Desktop.
get the real height of an element
This file contains hidden or 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
| /** | |
| * getRealHeight( elem ) | |
| * Get the real height of the given element. | |
| */ | |
| getRealHeight | |
| = function ( elem ) { | |
| var D = YAHOO.util.Dom; | |
| var _pos = D.getStyle(elem, 'position'); | |
| var _vis = D.getStyle(elem, 'visibility'); | |
| var clipped = false; | |
| // We don't want 0 height! | |
| if ( parseInt( elem.style.height ) == 0 ) { | |
| elem.style.display = "none"; | |
| elem.style.height = "" | |
| } | |
| if (elem.style.display == 'none') { | |
| clipped = true; | |
| D.setStyle(elem, 'position', 'absolute'); | |
| D.setStyle(elem, 'visibility', 'hidden'); | |
| D.setStyle(elem, 'display', 'block'); | |
| } | |
| var height = elem.offsetHeight; | |
| if (height == 'auto') { | |
| //This is IE, let's fool it | |
| D.setStyle(elem, 'zoom', '1'); | |
| height = elem.clientHeight; | |
| } | |
| if (clipped) { | |
| D.setStyle(elem, 'display', 'none'); | |
| D.setStyle(elem, 'visibility', _vis); | |
| D.setStyle(elem, 'position', _pos); | |
| } | |
| //Strip the px from the style | |
| return parseInt(height); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment