Skip to content

Instantly share code, notes, and snippets.

@preaction
Created November 1, 2010 16:56
Show Gist options
  • Select an option

  • Save preaction/658491 to your computer and use it in GitHub Desktop.

Select an option

Save preaction/658491 to your computer and use it in GitHub Desktop.
get the real height of an element
/**
* 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