目录
获取方法
getBoundingClientRect/ offsetWidth
var element = document.querySelector('...');
var scaleX = element.getBoundingClientRect().width / element.offsetWidth;
computedStyle
var matrixRegex = /matrix\((-?\d*\.?\d+),\s*0,\s*0,\s*(-?\d*\.?\d+),\s*0,\s*0\)/,
matches = $(element).css('-webkit-transform').match(matrixRegex);
-o-transform -moz-transformand -ms-transform
node = $("#yourid")[0];
var curTransform = new WebKitCSSMatrix(window.getComputedStyle(node).webkitTransform);
alert(curTransform.a);
alert(curTransform.d);
var element = document.getElementById("elementID");
var matrix = window.getComputedStyle(element).transform;
var matrixArray = matrix.replace("matrix(", "").split(",");
var scaleX = parseFloat(matrixArray[0]);
var scaleY = parseFloat(matrixArray[3]);
var translateX = parseFloat(matrixArray[4]);
var translateY = parseFloat(matrixArray[5]);
来源
get-the-scale-value-of-an-element