SVG SMIL animateTransform 缓动

标签 svg svg-animate

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

<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/ ,黑色应该有缓和

最佳答案

<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 缓动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26926999/

相关文章:

html - CSS改变svg元素的路径

javascript - 使用 Jquery 通过附加 <animate> 来更改 SVG 颜色,为什么它不起作用?

javascript - SVG 矩形的一致填充

javascript - 如何在自定义 highcharts 按钮中垂直居中文本

css - 如何以百分比填充svg图像的背景颜色

javascript - innerHTML 在 SVG 上无法正常工作?

html - SVG蜂窝多边形填充动画

css - 旋转 SVG mask

SVG .end 事件不起作用?

java - 如何加载和解析 SVG 文档