SVG SMIL animateTransform easing

和自甴很熟 提交于 2019-12-10 13:32:01

问题


I am trying to add a timing function to a simple SVG SMIL animation. Apparently timing/easing can be set with the keySplines attribute, however in my example it does not work:

<svg xmlns="http://www.w3.org/2000/svg" width="214" height="214" viewBox="0 0 24 24">

    <rect style="fill:#000;" width="4" height="4" x="3" y="11">
        <animateTransform attributeName="transform" 
        begin="0s" dur="2s" type="translate" from="0 0" to="40 0" repeatCount="4" fill="freeze"
        calcMode="spline"
        keySplines="0.4, 0, 0.2, 1"/>
    </rect>

    <rect style="fill:#ff0000;" width="4" height="4" x="3" y="16">
        <animateTransform attributeName="transform" 
        begin="0s" dur="2s" type="translate" from="0 0" to="40 0" repeatCount="4" fill="freeze" />
    </rect>

</svg>

Here is a demo: http://jsfiddle.net/q4e4049s/ , the black one should have easing


回答1:


<svg xmlns="http://www.w3.org/2000/svg" width="100%" viewBox="0 0 50 50">
	<rect style="fill:#000;" width="4" height="4" x="3" y="11">
		<animateTransform
      attributeName="transform" 
      begin="0s"
      dur="2s"
      type="translate"
      from="0 0"
      to="40 0"
      repeatCount="4"
      fill="freeze"
      calcMode="spline"
      keySplines="0.4 0 0.2 1; 0.4 0 0.2 1"
      values="0;30;0"
    />
	</rect>
	<rect style="fill:#ff0000;" width="4" height="4" x="3" y="16">
		<animateTransform
      attributeName="transform" 
      begin="0s"
      dur="2s"
      type="translate"
      from="0 0"
      to="40 0"
      repeatCount="4"
      fill="freeze"
    />
	</rect>
</svg>


来源:https://stackoverflow.com/questions/26926999/svg-smil-animatetransform-easing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!