Get the scale value of an element?

后端 未结 5 1919
别跟我提以往
别跟我提以往 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:19

    Too late for the OP but might be useful in the future. There is a straightforward way to do it using splits:

    function getTransformValue(element,property){       
            var values = element[0].style.webkitTransform.split(")");
            for (var key in values){
                var val = values[key];              
                var prop = val.split("(");          
                if (prop[0].trim() == property)
                    return prop[1];
            }                   
            return false;           
        }
    

    This is webkit specific, but can easily be extended for more browsers modifying the fist line.

提交回复
热议问题