Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get actual (not original) height of a CSS-rotated element

I need to obtain actual height of several different elements (for the sake of precise custom tooltip positioning), and some of these elements (not all) are rotated. $(elem).outerHeight() returns the original height, instead of the actual displayed height.

Here's the fiddle with a very simple example: http://jsfiddle.net/NPC42/nhJHE/

I see a possible solution in this answer: https://stackoverflow.com/a/8446228/253974, but am still hoping there is a simpler way.

like image 296
NPC Avatar asked Mar 20 '12 16:03

NPC


1 Answers

Dusting off my high school geometry and my formidable graphics skills, I put this diagram together. If you have variables width, height, and rotation in javascript, you could express the height this way:

var rotated_height = width * Math.sin(rotation) + height * Math.cos(rotation);

enter image description here

like image 90
recursive Avatar answered Oct 03 '22 21:10

recursive