Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A jQuery method that attempts to calculate the angle of rotation of the given HTML element.
$.fn.getPureRotation = function(element) {
var degrees = null;
$.each(['-webkit-transform', '-moz-transform', '-o-transform', '-sand-transform', '-ms-transform', 'transform'], function(index, value) {
var matrix = $(element).css(value);
if(degrees == null || Boolean(matrix)) {
var arrMatrix = matrix.match(/[\-0-9.]+/g);
if(
(parseFloat(arrMatrix[1]) == (-1 * parseFloat(arrMatrix[2]))) ||
(parseFloat(arrMatrix[3]) == parseFloat(arrMatrix[0])) ||
((parseFloat(arrMatrix[0]) * parseFloat(arrMatrix[3]) - parseFloat(arrMatrix[2]) * parseFloat(arrMatrix[1])) == 1)
) {
degrees = Math.round(Math.acos(parseFloat(arrMatrix[0])) * 180 / Math.PI);
} else {
degrees = 0;
}
}
});
return degrees;
};
@chrisbod

Hi there just to let you know this doesnt work for values over 180 (it gives 360-rotation) e.g. rotating 185 gives 175

@chrisbod

and negative values are return correctly but positive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.