influxweb
6/13/2017 - 9:04 PM

This function works if the element, or its parent, have been hidden via JavaScript, and can either retrieve inner or outer dimensions as wel

This function works if the element, or its parent, have been hidden via JavaScript, and can either retrieve inner or outer dimensions as well as returning the offset values. The function is called directly on the object and will insert a clone just after the original element making it possible for the clone to maintain inherited dimensions.

$.fn.getRealDimensions = function (outer) {
	var $this = $(this);
	
	if ($this.length === 0) {
		return false;
	}
	
	var $clone = $this.clone()
		.show()
		.css('visibility', 'hidden')
		.insertAfter($this);
	
	var result = {
		width: (outer) ? $clone.outerWidth() : $clone.innerWidth(),
		height: (outer) ? $clone.outerHeight() : $clone.innerHeight(),
		offsetTop: $clone.offset().top,
		offsetLeft: $clone.offset().left
	};
	
	$clone.remove();
	return result;
}

var dimensions = $('.hidden').getRealDimensions();