22

W3C 的规范中,它说:

'transform' 属性的值是一个<transform-list>,它被定义为一个变换定义的列表,这些定义按照提供的顺序应用。

...

如果提供了变换列表,那么最终效果就像每个变换都按照提供的顺序单独指定

当我在 firefox、chrome 和 IE10 中尝试以下标记时,所有三个都是先翻译,然后旋转!请参阅codepen 片段。我在这里错过了什么?或者 3 个浏览器的实现不符合 W3C?

<svg width="180" height="200"
  xmlns="http://www.w3.org/2000/svg" 
  xmlns:xlink="http://www.w3.org/1999/xlink">

  <!-- This is the element before translation and rotation are applied -->
  <rect x="0" y="0" height="100" width="100" style="stroke:#000; fill: #0086B2" fill-opacity=0.2 stroke-opacity=0.2></rect>

  <!-- Now we add a text element and apply rotate and translate to both -->
  <rect x="0" y="0" height="100" width="100" style="stroke:#000; fill: #0086B2" transform="rotate(45 100 50) translate(50)"></rect>
</svg>
4

2 回答 2

24

规范非常清楚首先应用最右边的变换的顺序。

如果提供了转换列表,那么最终效果就像每个转换都按照提供的顺序单独指定。

IE,

<g transform="translate(-10,-20) scale(2) rotate(45) translate(5,10)">
  <!-- graphics elements go here -->
</g>

在功能上等同于:

<g transform="translate(-10,-20)">
  <g transform="scale(2)">
    <g transform="rotate(45)">
      <g transform="translate(5,10)">
        <!-- graphics elements go here -->
      </g>
    </g>
  </g>
</g>
于 2013-09-03T08:27:37.767 回答
0
If you want to sequentially change these transformations 
you have to try this one

<g transform="translate(-10,-20)  onmouseover=changeTransform(evt)">

function changeTransfrom(evt)
{
var id=evt.target;
id.setAttribute('transform',scale(0.5));
id.setAttribute('transform',rotate(30));
id.setAttribute('transform',skewY(45));
id.setAttribute('transform',matrix(2,2));
}
于 2015-07-06T12:55:16.413 回答