1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| <!DOCTYPE html> <html lang="en">
<head> <meta charset="UTF-8"> <title>Document</title> </head> <style> #divTransform { margin: 30px; width: 200px; height: 100px; background-color: yellow; transform: rotate(9deg); -ms-transform: rotate(9deg); -moz-transform: rotate(9deg); -webkit-transform: rotate(9deg); -o-transform: rotate(9deg); } </style>
<body> <div id="divTransform"> </div> </body> <script> var el = document.getElementById("divTransform"); var st = window.getComputedStyle(el, null); var tr = st.getPropertyValue("-webkit-transform") || st.getPropertyValue("-moz-transform") || st.getPropertyValue("-ms-transform") || st.getPropertyValue("-o-transform") || st.getPropertyValue("transform") || "FAIL";
console.log('Matrix: ' + tr);
var values = tr.split('(')[1].split(')')[0].split(','); var a = values[0]; var b = values[1]; var c = values[2]; var d = values[3];
var scale = Math.sqrt(a * a + b * b);
console.log('Scale: ' + scale);
var sin = b / scale;
var angle = Math.round(Math.atan2(b, a) * (180 / Math.PI));
console.log('Rotate: ' + angle + 'deg'); </script>
</html>
|