jquery - Get number of CSS3 rotation cycles from matrix3d -


i trying rotate image using css3 rotatey. need angle of rotation using jquery.

my problem understanding how many cycles image has rotated.

example:

180 degrees: matrix3d(-1, 0, -0.00000000000000012246467991473532, 0, 0, 1, 0, 0, 0.00000000000000012246467991473532, 0, -1, 0, 0, 0, 0, 1)  360 degrees: matrix3d(1, 0, 0.00000000000000024492935982947064, 0, 0, 1, 0, 0, -0.00000000000000024492935982947064, 0, 1, 0, 0, 0, 0, 1) 540 degrees: matrix3d(-1, 0, -0.00000000000000036739403974420594, 0, 0, 1, 0, 0, 0.00000000000000036739403974420594, 0, -1, 0, 0, 0, 0, 1)  720 degrees: matrix3d(1, 0, 0.0000000000000004898587196589413, 0, 0, 1, 0, 0, -0.0000000000000004898587196589413, 0, 1, 0, 0, 0, 0, 1) 

as can see each 180 degrees, absolute value of third element adds 0.00000000000000012246467991473532. satisfied result, @ point logic breaks , not apply more.

after 4th cycle numbers being added become random.

what correct way number of rotation cycles?

-------------------------- tl;dr --------------------------

function getrotationcycle (domelement, axis) {      var computedstyle = window.getcomputedstyle(domelement),         matrixstyle = computedstyle.transform || computedstyle.webkittransform || computedstyle.moztransform || computedstyle.mstransform || computedstyle.otransform || computedstyle.khtmltransform;      if (!matrixstyle || matrixstyle.substr(0, 9) !== 'matrix3d(') {         //return 0; //????         throw "something's wrong 3d transform style. no style applied @ or unknown css3 vendor or unknown/unsupported 3d matrix representation string or css3 3d transform not supported in browser";     }      var matrix = webkitcssmatrix && (new webkitcssmatrix(matrixstyle)) ||                   mozcssmatrix && (new mozcssmatrix(matrixstyle)) ||                   mscssmatrix && (new mscssmatrix(matrixstyle)) ||                   ocssmatrix && (new ocssmatrix(matrixstyle)) ||                       cssmatrix && (new cssmatrix(matrixstyle)));      if (!matrix || isnan(matrix.a) || isnan(matrix.b) || isnan(matrix.c)) {         //not sure versions of firefox         throw "could not catch cssmatrix constructor current browser, or constructor has returned non-standard matrix object (need [a b c] numerical properties work)";     }      var rotation;       // todo: giving axis array idea, or return 3 rotations if no parameter given      switch (axis.touppercase()) {         case 'x':             rotation = math.acos(matrix.a);             break;          case 'y':             rotation = math.asin(matrix.b);             break;          case 'z':             throw "todo: sorry, math people. need here! please implement case me. you: http://9elements.com/html5demos/matrix3d/";             //rotation = math.acos(matrix.a);             break;         default:             throw "this function accepts rotation axis name (string) first parameter. possible values: 'x', 'y', 'z'";      }      //if (isnan(rotation))...      rotation *= 180/math.pi; //getting rotation in degrees. me debug purposes bad performance, of course, ...      return rotation % 360; // ... can skip degrees , in radians } 

some more great documentation given here: https://developer.mozilla.org, google , microsoft seems have nothing useful, apple has some.


everything has begun article: css3 converting matrix3d values. author starting point , math conversions.

but answer given there not complete, works in webkit only.

working code has been written in plain javascript because: - can copy-pasted environment - works bit (or much, depends) faster

if want jquery version, use snippet matrixstyle string.

var matrixstyle = element$.css('transform')) || element$.css('-webkit-transform')) || element$.css('-moz-transform')) || element$.css('-ms-transform')) || element$.css('-o-transform')); // jquery 

each part of matrix explained here : http://9elements.com/html5demos/matrix3d/


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -