Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SVG animation opacity on loop

I would like to make an svg path's opacity to go from 0 to 100 back to 0 and to 100 on a continuous loop.

So far i can get it to animate from 0 to 100 but not back again,

Any ideas?

Thanks

like image 552
John Vaughan Avatar asked Aug 06 '12 12:08

John Vaughan


People also ask

What does the opacity attribute do in SVG?

« SVG Attribute reference home. The opacity attribute specifies the transparency of an object or of a group of objects, that is, the degree to which the background behind the element is overlaid.

How are the animated loops stored in the icon?

In the previous version of the animated loops, the animation was stored into the icon SVG code as a <script>. In the new version, the animation is created using CSS.

What does opacity mean in HTML?

The opacity attribute specifies the transparency of an object or of a group of objects, that is, the degree to which the background behind the element is overlaid. Note: As a presentation attribute, opacity can be used as a CSS property. See the css opacity property for more information.

What does it mean to animate the opacity of a brush?

Animating the Opacity of a Brush provides performance benefits over animating the Opacity property of an element. In the following example, two buttons are animated so that they fade in and out of view. The Opacity of the first Button is animated from 1.0 to 0.0 over a Duration of five seconds.


2 Answers

You can animate any number of values using the values attribute, like this:

<rect x="10" y="10" width="20" height="20">
    <animate attributeName="opacity"
             values="0;1;0" dur="1s"
             repeatCount="indefinite"/>
</rect>

That will animate from opacity 0 to opacity 1 (100%), and then back to 0 again, over the course of 1 second.

like image 75
Erik Dahlström Avatar answered Jan 04 '23 08:01

Erik Dahlström


You have two separate animations - one for opacity increasing and one for it decreasing. Each begins when the other ends, but the first one also begins at 0s. Here's an example for a rect:

<rect x="10" y="10" width="20" height="20">
    <animate id="animation1"
             attributeName="opacity"
             from="0" to="1" dur="1s"
             begin="0s;animation2.end" />
    <animate id="animation2"
             attributeName="opacity"
             from="1" to="0" dur="1s" 
             begin="animation1.end" />
</rect>
like image 22
Peter Collingridge Avatar answered Jan 04 '23 09:01

Peter Collingridge