Skip to content

Instantly share code, notes, and snippets.

@adamcbrewer
Created December 4, 2012 09:42
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adamcbrewer/4202226 to your computer and use it in GitHub Desktop.
Save adamcbrewer/4202226 to your computer and use it in GitHub Desktop.
JS: CSS transform-martrix to rotation in degrees
/**
* Returns rotation in degrees when obtaining transform-styles using javascript
* http://stackoverflow.com/questions/8270612/get-element-moz-transformrotate-value-in-jquery
*/
function getRotationDegrees(obj) {
var matrix = obj.css("-webkit-transform") ||
obj.css("-moz-transform") ||
obj.css("-ms-transform") ||
obj.css("-o-transform") ||
obj.css("transform");
if(matrix !== 'none') {
var values = matrix.split('(')[1].split(')')[0].split(',');
var a = values[0];
var b = values[1];
var angle = Math.round(Math.atan2(b, a) * (180/Math.PI));
} else { var angle = 0; }
return angle;
}
angle1 = getRotationDegrees($('#myDiv'));
angle2 = getRotationDegrees($('.mySpan a:last-child'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment