//Get the SVG root for context
var s = document.getElementById('mysvg');
//Get a reference to the element
var t = document.getElementById('mytext');
//Find the transformation that would need to be applied to s to put it in the same co-ordinate space as t
var m = s.getTransformToElement(t);
2 回答
它返回Transformation Matrix,我现在不会太担心其他术语 . 如果您有这样的SVG:
然后你可以像这样使用
getTransformToElement
:在代码结束时,m将是一个表示矩阵的对象(也有一堆方法,但我忽略了它们):
然后,您可以使用该矩阵将相对于
mysvg
的相同变换应用于任何其他元素,与SVG规范中的矩阵乘法相对应:如下面的评论中所述,此方法已弃用,以支持getCTM in the upcoming SVG 2 standard .
可能的替代品
是