why doesn't looping smil animation in svg work as expected - svg

I perform smil animation where I want fill to loop between two values ; this is what I use to
<polygon points="500,519 512.5,540 537.5,540 550,519 537.5,498 512.5,498" class="hex" id="259">
<animate attributeName="fill" values="#080808;#82A1FF;080808" dur="4s" fill="freeze" begin="0" repeatCount="indefinite"></animate>
</polygon>
It does loop but seem it stuck on fill#82A1FF for the most of the 4 seconds ,it only slighly appears to move towards fill #080808 but rolls back to fill#82A1FF again.
I want the animation to be more uniform ,like a blinking light.
But now it looks like it is easing too much.

Related

Hiding an element with animaion in SVG file

<g id="Closed_Eyes">
<path d="Closed eye data" />
</g>
<g id="Open_Eyes">
<animate dur="0" attributeName="opacity" from="1" to="0" repeatCount="indefinite" />
<path d="Open eye data" />
</g>
I have an SVG face and like to animate blinking eyes. The animate does not work because the duration is zero, but if I change zero to some time, it is animate opacity. I should not be using opacity but I must use hiding on the open_Eyes object. The idea is that if we hide open_Eyes, the background close_Eyes shows and then shows. This will give if eyes are blinking. Kindly guide me on how we can animate blinking with animate.
I tried with opacity, but it changes the opacity with time. That is wrong. Perhaps I need two animations. First, hide the open_Eyes object and then show it.
Using dur="0" in animate won't work. If you just want to toggle the object you could either use a really small duration value (wouldn't recommend it though) or use the set tag like this:
<animate dur="0.001s" attributeName="opacity" from="1" to="0" repeatCount="indefinite" />
or this
<set attributeName="visibility" to="hidden" fill="freeze" />
You also dont need the repeatCount if you just want it to stay invisible or when using no duration. Use fill="freeze" instead, as seen in the second code example i made, to keep the state after the animation finished.

How to continue to the end of duration for indefinite animation on mouse out

I want to create an SVG that has the animation attributes that can continue the animation on mouse over.
On mouse out, I want the animation to continue to its end of duration before ending.
I am unable to achieve this as my animation always ends abruptly.
<svg viewBox="0 0 300 100" xmlns="http://www.w3.org/2000/svg">
<!-- Simple color fill -->
<circle cx="50" cy="50" r="40" fill="teal" >
<animate attributeName="fill" values="teal;cyan;teal;" dur="1s" calcMode="paced" repeatCount="indefinite" begin="mouseover" end="mouseout" />
</circle>
</svg>
Understand that we can achieve a slightly seamless feel by adding the fill="freeze" attribute.
However it brings back the issue of the colour not being the same as from where it left off.
Any idea how we can create a smooth animation on mouse over just by using svg attributes?
I hope to not use Javascript.

animateTransform moves an object despite beginning and end values being the same

I keep some text (Click to rerun) below the SVG bounding area until an animation ends. I then use animateTransform to move the text up to the middle of the screen. When the user clicks I use another animateTransform to move the text back below the screen until the animation ends. Below are the two animateTransforms. Note that the start and end values of clickAniHide are both 0,0, yet this moves the text off of the screen correctly! If I remove this animateTransform the text does not move. The text object is in the defs tag and is referenced by a tag. The text object is not within any container that could be moving it.
For simplicity I'm posting just the relevant animateTransforms to start, but I will post more/all of the code if necessary. Thanks!
<animateTransform
id="clickAniShow"
xlink:href="#rerun"
attributeType="XML"
attributeName="transform"
type="translate"
calcmode="discrete"
dur="0.1s"
begin="boxani2.end+0.75s;"
keyTimes="0; 1"
values="0, 0; 0, -350;"
fill="freeze"
/>
<animateTransform
id="clickAniHide"
xlink:href="#rerun"
attributeType="XML"
attributeName="transform"
type="translate"
calcmode="discrete"
dur="0.1s"
begin="restarter.click+0.2s;"
keyTimes="0; 1"
values="0,0; 0,0;"
fill="freeze"
/>
By default, the values in an animation replace any previous value the attribute had.
For your first animation, at 0s, transform(0,0) is set, and at 0.1s, transform(0,-350) is set and remains there according to the fill="freeze" rule.
For your second animation, at 0s, transform(0,0) is set, and at 0.1s, transform(0,0) is set again. Remember, before that animation, but after the first it was attransform(0,-350).
There are two additional rules you can set:
additive="sum": If your text element had for example a transform="scale(...)" attribute before any animation starts, the animation would not replace that value, but translate the already scaled element.
accumulate="sum": If an element has multiple animations, one animation starts at the end state of the previous, just like you expected to happen here.
It should be calcMode, not calcmode by the way.
As for SMIL animation support, Edge and Internet Explorer do not support SMIL animations at all. Starting with IE 10 you can use CSS animations instead. I can't immediately spot why you have a problem with Firefox.

is there a resizing animation for SVG element

What I have is some svg element produced by JS code on the fly such as lines and circles that consist of some geometry figure, what I want to achieve is to try to rescale the figure continuously using svg animation feature. I mean of course I could recompute the coordinates of each point of the line and center point of the circle and start from there but that would be a too tedious solution how can I do better?
Thanks a lot!
Put them in a <g> element and then give that <g> a transform attribute like transform="scale(1)" and animate that using a child <animateTransform> element. Something like this perhaps...
<animateTransform attributeName="transform"
attributeType="XML" type="scale" from="1" to="3"
additive="sum" begin="1s" dur="5s" fill="freeze"/>

Chrome SVG: Reusing animation element with fill="freeze" does not work as expected

I am supporting some old SVG graphics that we have in our application. I am having some issues with animating the fill color of a rectangle, and I am wondering if anyone else has seen the same issue.
We setup an animate element on the rec which ends up looking like this:
<svg id="svgEle" xmlns="http://www.w3.org/2000/svg" version="1.1">
<rect id="rect"
width="100" height="100"
style="fill:#008000; stroke:#000000;">
<animate id="animate" fill="freeze"
attributeName="fill" attributeType="CSS"
begin="indefinite" dur="1s"></animate>
</rect>
</svg>
And then, depending on values from a webservice result, we change the color of the rect and attempt to animate the color change. Currently it seems as if Chrome is the only native SVG render that supports the beginElement function. The animation works perfect on the first run, but all subsequent attempts to update the animation do not behave as expected. They always seem to revert to the first animation's fill color.
I have created the following example to show what I mean: http://jsfiddle.net/ssawchenko/ARXbs/
In Chrome the rectangle SHOULD cycle through all 4 colors via an animation when you click on the button, but it does not. In IE9 animation is not supported, so the fill color is just changed directly.
I am ok with IE9 simply setting the fill, however, in Chrome the colors are completely busted. Does anyone know if this is a bug, or if there is a work around?
Thanks!
This bug also exhibits in SVG Edit.
<animate attributeName="opacity" begin="indefinite" dur="1" fill="freeze">
</animate>
If you draw rectangles on top of each other you will see they seem semitransparent when they should be fully opaque. I've seen that Chrome Canary doesn't exhibit this behaviour, so it might be fixed in the next release.
I think this filed bug is related.

Resources