本文介紹了在jQuery中獲取元素-moz-transform:旋轉值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我有一個圖層的 CSS 樣式:
I have CSS style for a layer:
.element {
-webkit-transform: rotate(7.5deg);
-moz-transform: rotate(7.5deg);
-ms-transform: rotate(7.5deg);
-o-transform: rotate(7.5deg);
transform: rotate(7.5deg);
}
有沒有辦法通過 jQuery 獲取當前的旋轉值?
Is there a way to get curent rotation value through jQuery?
我試過了
$('.element').css("-moz-transform")
結果是 matrix(0.991445, 0.130526, -0.130526, 0.991445, 0px, 0px)
這并沒有告訴我很多.我想要的是 7.5
.
The result is matrix(0.991445, 0.130526, -0.130526, 0.991445, 0px, 0px)
which doesn't tell me a lot. What I'm looking to get is 7.5
.
推薦答案
這是我使用 jQuery 的解決方案.
Here's my solution using jQuery.
這會返回一個數值,對應于應用于任何 HTML 元素的旋轉.
This returns a numerical value corresponding to the rotation applied to any HTML element.
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 < 0) ? angle + 360 : angle;
}
angle1 = getRotationDegrees($('#myDiv'));
angle2 = getRotationDegrees($('.mySpan a:last-child'));
等等……
這篇關于在jQuery中獲取元素-moz-transform:旋轉值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!