Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG SMIL animateTransform easing

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

like image 885
Mircea Avatar asked Nov 14 '14 09:11

Mircea


People also ask

What is Smil SVG?

Firefox 4 introduced support for animating SVG using Synchronized Multimedia Integration Language (SMIL). SMIL allows you to: animate the numeric attributes of an element (x, y, …) animate transform attributes (translation or rotation) animate color attributes.

What is animateTransform?

<animateTransform> The animateTransform element animates a transformation attribute on its target element, thereby allowing animations to control translation, scaling, rotation, and/or skewing.

Is it possible to animate SVG?

Overview. SVG graphics can be animated using animation elements. The animation elements were initially defined in the SMIL Animation specification; these elements include: <animate> – which allows you to animate scalar attributes and properties over a period of time.


1 Answers

<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>
like image 102
Angelo Lucas Avatar answered Oct 19 '22 09:10

Angelo Lucas