// Suppose the transformed element is called "cover".
var element = document.getElementById('cover');
computedStyle = window.getComputedStyle(element, null); // "null" means this is not a pesudo style.
// You can retrieve the CSS3 matrix string by the following method.
var matrix = computedStyle.getPropertyValue('transform')
|| computedStyle.getPropertyValue('-moz-transform')
|| computedStyle.getPropertyValue('-webkit-transform')
|| computedStyle.getPropertyValue('-ms-transform')
|| computedStyle.getPropertyValue('-o-transform');
// Parse this string to obtain different attributes of the matrix.
// This regexp matches anything looks like this: anything(1, 2, 3, 4, 5, 6);
// Hence it matches both matrix strings:
// 2d: matrix(1,2,3,4,5,6)
// 3d: matrix3d(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
var matrixPattern = /^\w*\((((\d+)|(\d*\.\d+)),\s*)*((\d+)|(\d*\.\d+))\)/i;
var matrixValue = [];
if (matrixPattern.test(matrix)) { // When it satisfy the pattern.
var matrixCopy = matrix.replace(/^\w*\(/, '').replace(')', '');
console.log(matrixCopy);
matrixValue = matrixCopy.split(/\s*,\s*/);
}
希望這有助於! 請注意,我沒有使用除普通DOM API和本機Javascript RegExp函數之外的其他庫。因此,這應該普遍跨瀏覽器和應用程序。
-webkit-轉換不是一個屬性,所以無法通過屬性訪問它,你應該訪問的風格與元素關聯的對象。 – shabunc 2011-07-21 20:15:11