2013-01-18 11 views
0

如何從元素(不包括值)中獲取當前應用的CSS屬性標識符?獲取應用的css屬性標識符

或者說:如何獲取元素translateskewrotaterect?我不是指完整的返回字符串,如:rect(300px 0px 0px 300px)。我的意思只是property-identifiers ...

我不是很熟悉RegExp,但也許可以做到這一點?

所以爲了更好的詮釋用途:

我需要檢查的是,改變一些值(通過矩陣陣列),並再次重新申請他們回到元素。

// http://stackoverflow.com/a/5968313/1250044 
function matrixToArray(matrix) { 
    return matrix.substr(7, matrix.length - 8).split(', '); 
} 

$("#foo").css("clip","rect(300px 0px 0px 300px)"); 
var matrix = matrixToArray($("#foo").css("clip")); 

           // If `#foo` has something else 
           // applied than `clip`, then 
        --- ˅ --- // is that not really dynamically 
$("#bar").css("clip", "rect(" + matrix[0] + matrix[1] + matrix[2] + matrix[3] + ")"); 
+0

您可以使用jQuery進行檢測。 – Morpheus

+0

@Pete閱讀我的問題,我需要沒有價值的財產...... – yckart

+0

也許這將幫助你http://stackoverflow.com/questions/1004475/jquery-css-plugin-that-returns-computed-style-of-元素 - 僞 - 克隆 - 那 - el – Morpheus

回答

0

明白了...

很簡單:

var getIdentifier = function(str) { 
    return str.split('(')[0]; 
}; 

getIdentifier('rect(300px 0px 0px 300px)') // => 'rect'

0

您可以使用window.getComputedStyle()

// your elemenet 
var el; 

// get the transformations applied: 
var transform = window.getComputedStyle(el).transform; 

然而這將,讓你在大多數的情況下,matrix,而不是應用各個轉換。

0

例如,

$(ele).css('rotate') 

要檢測,檢查是否返回長度> 0

$(ele).css('rotate').length 
+0

這並不能真正回答我的問題;) – yckart