Skip to content

Instantly share code, notes, and snippets.

@staaky
Created December 6, 2008 16:05
Show Gist options
  • Save staaky/32900 to your computer and use it in GitHub Desktop.
Save staaky/32900 to your computer and use it in GitHub Desktop.
getHiddenDimensions: function(element) {
element = $(element);
var check = element.ancestors(),
restore = [],
styles = [];
check.push(element);
// All *Width and *Height properties give 0 on elements with display none,
// or when ancestors have display none, so enable those temporarily
check.each(function(c) {
if (c != element && c.visible()) return;
restore.push(c);
styles.push({
display: c.getStyle('display'),
position: c.getStyle('position'),
visibility: c.getStyle('visibility')
});
c.setStyle({display: 'block', position: 'absolute', visibility: 'visible'});
});
var dimensions = {width: element.clientWidth, height: element.clientHeight};
restore.each(function(r, index) {
r.setStyle(styles[index]);
});
return dimensions;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment