Get the scale value of an element?

后端 未结 5 1923
别跟我提以往
别跟我提以往 2020-11-28 12:32

I\'m wondering how I can get the scale value of an element?

I have tried $(element).css(\'-webkit-transform\'); which returns matrix(scaleX,0,0,sc

5条回答
  •  天命终不由人
    2020-11-28 13:22

    If you need to target webkit only (because it's for the iPhone, or iPad) the most reliable and fast way is using the native javascript webkit provides:

    node = $("#yourid")[0];
    var curTransform = new WebKitCSSMatrix(window.getComputedStyle(node).webkitTransform);
    alert(curTransform.a); // curTransform is an object,
    alert(curTransform.d); // a through f represent all values of the transformation matrix
    

    You can view a demo here: http://jsfiddle.net/umZHA/

提交回复
热议问题