han4wluc han4wluc - 6 months ago 28
CSS Question

css transform. How to get rotation degree value from "matrix( 0, 1, -1, 0, 0, 0")?

How to convert this matrix into degrees?

I'm rotating a

div
with
transform: rotate()
. And I want to get the rotation value.

When I try
$( icon ).css('transform')
, it returns a matrix value like
matrix(0, 0, 0, 0, 0, 0)
.

My question is how do I convert the matrix value into degree value?

This is what I've found:

0° matrix( 0, 0, 0, 0, 0, 0)
45° matrix( .7, .7, -.7, .7, 0, 0)
90° matrix( 0, 1, -1, 0, 0, 0)
180° matrix( -1, 0, 0, -1, 0, 0)
270° matrix( 0, -1, 1, 0, 0, 0)


Sorry if this is more of a math question...

Answer

Without being a mathematician, you can parse the rotation angle from the style.

var style = $(el).attr('style'),
    rotation = parseInt(style.substr(style.indexOf("rotate("+7));

Note: This works because jQuery modifies the style attribute. If you set the rotation in CSS initially, it won't work.