I've created a basic svg animation which loops every 750ms, however once it's finished a single animation loop it jumps back to the beginning giving it an ugly hard cut look.
<animate attributeName="stop-opacity" from="0.99" to="0.20" dur="750ms" repeatCount="indefinite" />
Is it possible that once the opacity goes from 0.99
down to 0.20
it will work its way back up to 0.99
instead of instantly jumping back to the start variable?
Example fiddle
SVG supports the ability to change vector graphics over time, to create animated effects. SVG content can be animated in the following ways: Using SVG's animation elements [svg-animation].
a) Using an <img> tag For example <img src="sample. svg" /> . Please note that interactivity for <img> tags are disallowed in most browsers, so in case you've selected 'Animate on mouse over' for your SVG when you've exported it, this will not work with an <img> tag. You can use an <object> tag instead.
You can specify multiple values by using the values
attribute on animate
. Using this, you could specify to go back to the original opacity or even add more opacity values:
<animate attributeName="stop-opacity" values="0.99;0.20;0.99" dur="750ms" repeatCount="indefinite" />
Here is a working example. There is no out of the box way to have an animation go back and forth using SMIL, but you can use a workaround that starts a secondary animation after the first that is a backwards animation. This will loop and give the effect of your SVG fading in and out.
<animate id="anim1"attributeName="stop-opacity" from="0.99" to="0.20" dur="750ms" begin="0s; anim2.end" fill="freeze"/>
<animate id="anim2"attributeName="stop-opacity" from="0.20" to="0.99" dur="750ms" begin="anim1.end" fill="freeze"/>
Those are the two lines that I changed. Notice I have the second animation start once the first ends and the first one start after the second one ends (looping between the two).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With