Get the current matrix transformation of an SVG element

后端 未结 3 878
北恋
北恋 2021-01-05 13:32

I know a very easy way to get the current matrix transformation of any SVG element:

// \'t\' is a string
var t = window.getComputedStyle(nativeElement, null)         


        
3条回答
  •  灰色年华
    2021-01-05 13:46

    Consolidation can change your element 'transform' attribute value. You can also get a matrix without changing the transformation attribute by transforming the element matrix to the parent.

    See documentation about the:

    getTransformToElement
    

    function getMatrix(element) {
      var matrix = element.parentNode
         .getScreenCTM()
         .inverse()
         .multiply(element.getScreenCTM());
      return matrix;
    }
    var myrect = document.getElementById("myrect");
    
    console.log(getMatrix(myrect));
    
      
    

提交回复
热议问题