SVG animation opacity on loop

John Vaughan picture John Vaughan · Aug 6, 2012 · Viewed 25.6k times · Source

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

Answer

Erik Dahlström picture Erik Dahlström · Aug 8, 2012

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.