SVG SMIL animateTransform缓动 [英] SVG SMIL animateTransform easing

查看:86
本文介绍了SVG SMIL animateTransform缓动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将计时功能添加到简单的SVG SMIL动画中.显然,可以使用keySplines属性设置计时/放松,但是在我的示例中,它不起作用:

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>

这是一个演示: http://jsfiddle.net/q4e4049s/,黑色的应该有放松

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

推荐答案

<svg xmlns="http://www.w3.org/2000/svg" width="100%" viewBox="0 0 50 14">
    <rect fill="black" width="6" height="6" x="3" y="0">
        <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 fill="red" width="6" height="6" x="3" y="7">
        <animateTransform attributeName="transform"
                          begin="0s"
                          dur="2s"
                          type="translate"
                          from="0 0"
                          to="40 0"
                          repeatCount="4"
                          fill="freeze"/>
    </rect>
</svg>

这篇关于SVG SMIL animateTransform缓动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆