Is there js plugin convert the matrix parameter to css3 transform property?

后端 未结 4 2112
萌比男神i
萌比男神i 2021-01-05 09:27

Suppose I have css3 transform style:

img
{
   -webkit-transform:rotate(10deg) translate(100px,20px);
   -moz-transform:rotate(10deg) translate(100px,20px);
}         


        
4条回答
  •  天涯浪人
    2021-01-05 10:01

    Do this:

    // Grab current rotation position
    var  $img,
         position;
    
    $img = $('img');
    
    position = $img.css('-webkit-transform') || $img.css('-moz-transform') || $img.css('-ms-transform') || $img.css('-o-transform') || $img.css('transform');
    
    position = position.split('(')[1].split(')')[0].split(',');
    
    // Concert matrix to degrees value
    position = Math.round(Math.atan2(position[1], position[0]) * (180/Math.PI));
    

    See Demo

    Learn more

提交回复
热议问题