Read css scale value using JS or Jquery

后端 未结 4 549
南笙
南笙 2021-01-25 02:24

I have this div

How do I get the

transform: scale(x,y) 
4条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-25 02:57

    Possible duplicate of Get the scale value of an element?:

    var matrixRegex = /matrix\((-?\d*\.?\d+),\s*0,\s*0,\s*(-?\d*\.?\d+),\s*0,\s*0\)/;
    var matches = $('#id').css('transform').match(matrixRegex);
    console.log(matches)
    
    

    That snippet will return an array with the original matrix, and then indexes 2 and 3 contain X and Y values, respectively. Credit to Lea Verou

提交回复
热议问题