Skip to content

Instantly share code, notes, and snippets.

@orioltf
Last active August 29, 2015 14:21
Show Gist options
  • Save orioltf/19ff5d0cb119f40adce4 to your computer and use it in GitHub Desktop.
Save orioltf/19ff5d0cb119f40adce4 to your computer and use it in GitHub Desktop.
#JQUERY #UTIL getHeightIn
/**
* Gets the height from the provided elements, even if they are hidden
* @param {Object} $context - the jQuery DOM element where to append the object so that it gets proper styling
* @returns {Number} - the outerHeight value from the passed $element
*/
$.fn.getHeightIn = function($context) {
var $element = this,
$wrap = $('<div />'),
$clone, height;
$context = typeof $context === 'undefined' ? $('body') : $context;
$wrap.css({
'position': 'absolute !important',
'visibility': 'hidden !important',
'display': 'block !important'
}).appendTo($context);
$clone = $element.clone();
$clone.appendTo($wrap);
height = $clone.outerHeight();
$wrap.remove();
return height;
};
collapsibleHeight = $collapsible.getHeightIn( $('#main') );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment