I did a simple loading icon with six rectangles that darken in series, my image is:
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 60 60">
<g transform="translate(30,30)">
<g transform="rotate(0)">
<rect id="rect1" x="-3" y="9" rx="3" ry="3" width="6" height="20">
<animateColor id="a1b" begin="0s;a6b.end" attributeName="fill" values="white;black" fill="freeze" dur=".5s" />
<animateColor id="a1w" begin="1s;a6w.end" attributeName="fill" values="black;white" fill="freeze" dur=".5s" />
</rect>
</g>
<g transform="rotate(60)">
<rect id="rect2" x="-3" y="9" rx="3" ry="3" width="6" height="20">
<animateColor id="a2b" begin="a1b.end" attributeName="fill" values="white;black" fill="freeze" dur=".5s" />
<animateColor id="a2w" begin="a1w.end" attributeName="fill" values="black;white" fill="freeze" dur=".5s" />
</rect>
</g>
⋮
<g transform="rotate(300)">
<rect id="rect6" x="-3" y="9" rx="3" ry="3" width="6" height="20">
<animateColor id="a6b" begin="a5b.end" attributeName="fill" values="white;black" fill="freeze" dur=".5s" />
<animateColor id="a6w" begin="a5w.end" attributeName="fill" values="black;white" fill="freeze" dur=".5s" />
</rect>
</g>
</g>
</svg>
When I initially created the document, this structure worked. Now it doesn't. Anyone know why?
The <animateColor> elements was deprecated in SVG 1.1 and is being completely removed for SVG 2. Some browsers are removing it already.
To achieve the same effect, just use <animate> with all the same attributes.
<svg xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
viewBox="0 0 60 60" style="width:100vmin">
<defs>
<title>Loading Icon</title>
<style type="text/css">
rect {
stroke: black;
stroke-width: .75;
fill: transparent;
}
</style>
<rect id="bar" x="-3" y="9" rx="3" ry="3" width="6" height="20"/>
</defs>
<g transform="translate(30,30)">
<g transform="rotate(0)">
<rect id="rect1" x="-3" y="9" rx="3" ry="3" width="6" height="20">
<animate id="a1b" attributeName="fill" values="white;black" fill="freeze" dur=".5s" begin="0s;a6b.end" />
<animate id="a1w" attributeName="fill" values="black;white" fill="freeze" dur=".5s" begin="1s;a6w.end" />
</rect>
</g>
<g transform="rotate(60)">
<rect id="rect2" x="-3" y="9" rx="3" ry="3" width="6" height="20">
<animate id="a2b" attributeName="fill" values="white;black" fill="freeze" dur=".5s" begin="a1b.end" />
<animate id="a2w" attributeName="fill" values="black;white" fill="freeze" dur=".5s" begin="a1w.end" />
</rect>
</g>
<g transform="rotate(120)">
<rect id="rect3" x="-3" y="9" rx="3" ry="3" width="6" height="20">
<animate id="a3b" attributeName="fill" values="white;black" fill="freeze" dur=".5s" begin="a2b.end" />
<animate id="a3w" attributeName="fill" values="black;white" fill="freeze" dur=".5s" begin="a2w.end" />
</rect>
</g>
<g transform="rotate(180)">
<rect id="rect4" x="-3" y="9" rx="3" ry="3" width="6" height="20">
<animate id="a4b" attributeName="fill" values="white;black" fill="freeze" dur=".5s" begin="a3b.end" />
<animate id="a4w" attributeName="fill" values="black;white" fill="freeze" dur=".5s" begin="a3w.end" />
</rect>
</g>
<g transform="rotate(240)">
<rect id="rect5" x="-3" y="9" rx="3" ry="3" width="6" height="20">
<animate id="a5b" attributeName="fill" values="white;black" fill="freeze" dur=".5s" begin="a4b.end" />
<animate id="a5w" attributeName="fill" values="black;white" fill="freeze" dur=".5s" begin="a4w.end" />
</rect>
</g>
<g transform="rotate(300)">
<rect id="rect6" x="-3" y="9" rx="3" ry="3" width="6" height="20">
<animate id="a6b" attributeName="fill" values="white;black" fill="freeze" dur=".5s" begin="a5b.end" />
<animate id="a6w" attributeName="fill" values="black;white" fill="freeze" dur=".5s" begin="a5w.end" />
</rect>
</g>
</g>
</svg>
Related
So i have page 1 and page 2 which are animated, inside of page 2 there is also animation but problem is that this object shows when page 2 is "hidden". How to prevent that ??
Black square should only be visible when page 2 is visible, but it ignores parent style.
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 612 792" style="enable-background:new 0 0 612 792;" xml:space="preserve">
<rect x="0.5" y="0.167" fill="#ccc" stroke="#000" width="100" height="100"/>
<!-- square -->
<g>
<!-- page 1 -->
<g id="page_one" style="z-index:1">
<rect x="25" y="5" width="50" height="50" fill="red" style=""></rect>
</g>
<!-- page 2 -->
<g id="page_two" style="z-index:-1">
<rect x="25" y="5" width="50" height="50" fill="white" style=""></rect>
<g transform="scale(2.9) translate(6,0)">
<g transform="scale(0.205)translate(1,1)">
<!-- animation inside page 2 -->
<g style="z-index:-1">
<animate attributeName="visibility" dur="2" repeatCount="indefinite" keyTimes="0;0.5;1" values="visible;hidden;visible"></animate>
<rect x="25" y="15" width="50" height="50" fill="black" style=""></rect>
</g>
</g>
</g>
</g>
<!-- animate page 1 & 2 -->
<animate xlink:href="#page_one" attributeName="visibility" values="visible;hidden" dur="4s" begin="0s" repeatCount="indefinite"></animate>
<animate xlink:href="#page_two" attributeName="visibility" values="hidden;visible" dur="4s" begin="0s" repeatCount="indefinite"></animate>
</g>
</svg>
Tried some css styling, z-index but nothing solved issue.
animate the display property instead.
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 612 792" style="enable-background:new 0 0 612 792;" xml:space="preserve">
<rect x="0.5" y="0.167" fill="#ccc" stroke="#000" width="100" height="100"/>
<!-- square -->
<g>
<!-- page 1 -->
<g id="page_one" style="z-index:1">
<rect x="25" y="5" width="50" height="50" fill="red" style=""></rect>
</g>
<!-- page 2 -->
<g id="page_two" style="z-index:-1">
<rect x="25" y="5" width="50" height="50" fill="white" style=""></rect>
<g transform="scale(2.9) translate(6,0)">
<g transform="scale(0.205)translate(1,1)">
<!-- animation inside page 2 -->
<g style="z-index:-1">
<animate attributeName="display" dur="2" repeatCount="indefinite" keyTimes="0;0.5;1" values="block;none;block"></animate>
<rect x="25" y="15" width="50" height="50" fill="black" style=""></rect>
</g>
</g>
</g>
</g>
<!-- animate page 1 & 2 -->
<animate xlink:href="#page_one" attributeName="display" values="block;none" dur="4s" begin="0s" repeatCount="indefinite"></animate>
<animate xlink:href="#page_two" attributeName="display" values="none;block" dur="4s" begin="0s" repeatCount="indefinite"></animate>
</g>
</svg>
I have a loader gif, but I want this animation using svg
[1]: https://i.stack.imgur.com/h3oJC.gif
Enjoy:
<svg>
<rect fill="blue" x="0" y="0" width="300" height="140"/>
<circle fill="white" cx="150" cy="70" r="60" stroke="blue" stroke-width="5" />
<path fill="none" stroke="blue" stroke-width="10" d="M0,0 Q 30,-30 60,0 Q 90,30 120,0 Q 150,-30 180,0 210,30 240,0">
<animateTransform attributeName="transform"
attributeType="XML"
type="translate"
from="-30 70"
to="90 70"
dur="1s"
repeatCount="indefinite"/>
</path>
</svg>
I cannot seem to get this mask to work with my animation in SVG. What is wrong with this code? The green arrow should be masked out from the rightmost side of the circle, so that the arrow appears to be consumed by the circle upon contact.
<svg height="200" width="1200" viewBox="0 0 200 200">
<defs>
<mask id="mask1" x="0" y="0" width="700" height="110" >
<rect x="0" y="0" width="550" height="110" style="stroke:none; fill:white" />
<rect x="550" y="0" width="50" height="110" style="stroke:none; fill:black"/>
</mask>
</defs>
<polygon id="arrow" z-index="1" points="0,5 0,105 105,55" mask="url(#mask1)" fill="green">
<animateTransform attributeName="transform" type="translate" attributeType="XML" values="0, 0; 550, 0; 550, 0" keyTimes="0; .7; 1" dur="3s" repeatCount="indefinite" additive="sum"/>
<animate attributeName="opacity" values="1; 1; 0" keyTimes="0; .5; 1" dur="3s" repeatCount="indefinite" />
</polygon>
<circle z-index="1" cx="550" cy="55" r="49" stroke-width="6" stroke="black" fill="gray"/>
<circle z-index="2" cx="550" cy="55" r="49" stroke-width="6" stroke="black" fill="none"/>
<circle id="greenCircle" z-index="2" cx="550" cy="55" r="49" stroke-width="6" stroke="green" fill="none"/>
<animate id="fillGreen" xlink:href="#greenCircle" attributeName="stroke-dasharray" values="154, 0, 154, 0; 0, 308, 0, 0; 0, 308, 0, 0" keyTimes="0; 0.5; 1" dur="3s" repeatCount="indefinite" />
<circle id="blackCircle" z-index="2" cx="550" cy="55" r="49" stroke-width="6" stroke="green" fill="none"/>
<animate id="fillBlack" xlink:href="#blackCircle" attributeName="stroke-dasharray" values="0, 154, 0, 154; 0, 154, 0, 154; 0, 0, 308, 0" dur="3s" keyTimes="0; 0.5; 1" repeatCount="indefinite" />
</circle>
</svg>
The transform applies to the mask too so as the polygon moves, so does the mask. You need to set the mask on something that doesn't move e.g.
<svg height="200" width="1200" viewBox="0 0 200 200">
<defs>
<mask id="mask1" x="0" y="0" width="700" height="110" >
<rect x="0" y="0" width="550" height="110" style="stroke:none; fill:white" />
<rect x="550" y="0" width="50" height="110" style="stroke:none; fill:black"/>
</mask>
</defs>
<g mask="url(#mask1)" >
<polygon id="arrow" z-index="1" points="0,5 0,105 105,55" fill="green">
<animateTransform attributeName="transform" type="translate" attributeType="XML" values="0, 0; 550, 0; 550, 0" keyTimes="0; .7; 1" dur="3s" repeatCount="indefinite" additive="sum"/>
<animate attributeName="opacity" values="1; 1; 0" keyTimes="0; .5; 1" dur="3s" repeatCount="indefinite" />
</polygon>
</g>
<circle z-index="1" cx="550" cy="55" r="49" stroke-width="6" stroke="black" fill="gray"/>
<circle z-index="2" cx="550" cy="55" r="49" stroke-width="6" stroke="black" fill="none"/>
<circle id="greenCircle" z-index="2" cx="550" cy="55" r="49" stroke-width="6" stroke="green" fill="none"/>
<animate id="fillGreen" xlink:href="#greenCircle" attributeName="stroke-dasharray" values="154, 0, 154, 0; 0, 308, 0, 0; 0, 308, 0, 0" keyTimes="0; 0.5; 1" dur="3s" repeatCount="indefinite" />
<circle id="blackCircle" z-index="2" cx="550" cy="55" r="49" stroke-width="6" stroke="green" fill="none"/>
<animate id="fillBlack" xlink:href="#blackCircle" attributeName="stroke-dasharray" values="0, 154, 0, 154; 0, 154, 0, 154; 0, 0, 308, 0" dur="3s" keyTimes="0; 0.5; 1" repeatCount="indefinite" />
</circle>
</svg>
below i create a simple fiddle with svg animation:
<svg width="250" height="250" viewbox="0 0 20 20">
<line x1="10" y1="0" x2="10" y2="10"style="stroke:rgb(255,0,0); stroke-width:1">
<animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 10 10" to="360 10 10" dur="7.5s" repeatCount="indefinite" />
</line>
<circle cx="5" cy="5" r="1" style="fill:rgb(0,255,0);"/>
<circle cx="15" cy="15" r="1" style="fill:rgb(0,0,255);"/>
</svg>
My question is: is there a way that I can make blue and red point bump (change their color for example) when red line hover them?
Thank you
This is my solution: I'm creating a mask with the line. There are 2 extra circles (fill:gold) that are masked by the line.
I'm putting the animated line inside a <g stroke="red"> because I want the used line to be white.
svg{border:1px solid;}
<svg width="250" height="250" viewbox="0 0 20 20">
<circle cx="5" cy="5" r="1" style="fill:rgb(0,255,0);" />
<circle cx="15" cy="15" r="1" style="fill:rgb(0,0,255);"/>
<mask id="mask">
<use xlink:href="#L" style="stroke:white"/>
</mask>
<g stroke="red">
<line id="L" x1="10" y1="0" x2="10" y2="10" >
<animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 10 10" to="360 10 10" dur="7.5s" repeatCount="indefinite" />
</line>
</g>
<g style="fill:gold;mask: url(#mask)">
<circle cx="5" cy="5" r="1" />
<circle cx="15" cy="15" r="1"/>
</g>
</svg>
Example, I want to make a SVG loader animation.
I got some transition / easing / delay when looping (I dont know what to call sorry)
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 590 100">
<circle id="a1" cx="70" cy="70" r="20"/>
<circle id="a2" cx="120" cy="70" r="20"/>
<circle id="a3" cx="170" cy="70" r="20"/>
<circle id="a4" cx="220" cy="70" r="20"/>
<circle id="a5" cx="270" cy="70" r="20"/>
<circle id="a6" cx="320" cy="70" r="20"/>
<circle id="a7" cx="370" cy="70" r="20"/>
<circle id="a8" cx="420" cy="70" r="20"/>
<circle id="a9" cx="470" cy="70" r="20"/>
<circle id="a10" cx="520" cy="70" r="20"/>
<animate xlink:href="#a1" attributeName="visibility" from="hidden" to="visible" begin="0.1s" dur="1s" repeatCount="indefinite" />
<animate xlink:href="#a2" attributeName="visibility" from="hidden" to="visible" begin="0.2s" dur="1s" repeatCount="indefinite" />
<animate xlink:href="#a3" attributeName="visibility" from="hidden" to="visible" begin="0.3s" dur="1s" repeatCount="indefinite" />
<animate xlink:href="#a4" attributeName="visibility" from="hidden" to="visible" begin="0.4s" dur="1s" repeatCount="indefinite" />
<animate xlink:href="#a5" attributeName="visibility" from="hidden" to="visible" begin="0.5s" dur="1s" repeatCount="indefinite" />
<animate xlink:href="#a6" attributeName="visibility" from="hidden" to="visible" begin="0.6s" dur="1s" repeatCount="indefinite" />
<animate xlink:href="#a7" attributeName="visibility" from="hidden" to="visible" begin="0.7s" dur="1s" repeatCount="indefinite" />
<animate xlink:href="#a8" attributeName="visibility" from="hidden" to="visible" begin="0.8s" dur="1s" repeatCount="indefinite" />
<animate xlink:href="#a9" attributeName="visibility" from="hidden" to="visible" begin="0.9s" dur="1s" repeatCount="indefinite" />
<animate xlink:href="#a10" attributeName="visibility" from="hidden" to="visible" begin="1s" dur="1s" repeatCount="indefinite" />
</svg>
Look at this demo :
Those dots doesnt gone when animation done.
I just want to show dot running (one dot) (current demo is showing about 4 dots running)
How should i do , what I am missing ?
Aha, I think I got it by using value
Example : (10 steps)
values="visible;hidden;hidden;hidden;hidden;hidden;hidden;hidden;hidden;hidden;"
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 590 100">
<circle id="a1" cx="70" cy="70" r="20"/>
<circle id="a2" cx="120" cy="70" r="20"/>
<circle id="a3" cx="170" cy="70" r="20"/>
<circle id="a4" cx="220" cy="70" r="20"/>
<circle id="a5" cx="270" cy="70" r="20"/>
<circle id="a6" cx="320" cy="70" r="20"/>
<circle id="a7" cx="370" cy="70" r="20"/>
<circle id="a8" cx="420" cy="70" r="20"/>
<circle id="a9" cx="470" cy="70" r="20"/>
<circle id="a10" cx="520" cy="70" r="20"/>
<animate xlink:href="#a1" attributeName="visibility" begin="0s" dur="1.3s" values="visible;hidden;hidden;hidden;hidden;hidden;hidden;hidden;hidden;hidden;" calcMode="linear" repeatCount="indefinite" />
<animate xlink:href="#a2" attributeName="visibility" begin="0s" dur="1.3s" values="hidden;visible;hidden;hidden;hidden;hidden;hidden;hidden;hidden;hidden;" calcMode="linear" repeatCount="indefinite" />
<animate xlink:href="#a3" attributeName="visibility" begin="0s" dur="1.3s" values="hidden;hidden;visible;hidden;hidden;hidden;hidden;hidden;hidden;hidden;" calcMode="linear" repeatCount="indefinite" />
<animate xlink:href="#a4" attributeName="visibility" begin="0s" dur="1.3s" values="hidden;hidden;hidden;visible;hidden;hidden;hidden;hidden;hidden;hidden;" calcMode="linear" repeatCount="indefinite" />
<animate xlink:href="#a5" attributeName="visibility" begin="0s" dur="1.3s" values="hidden;hidden;hidden;hidden;visible;hidden;hidden;hidden;hidden;hidden;" calcMode="linear" repeatCount="indefinite" />
<animate xlink:href="#a6" attributeName="visibility" begin="0s" dur="1.3s" values="hidden;hidden;hidden;hidden;hidden;visible;hidden;hidden;hidden;hidden;" calcMode="linear" repeatCount="indefinite" />
<animate xlink:href="#a7" attributeName="visibility" begin="0s" dur="1.3s" values="hidden;hidden;hidden;hidden;hidden;hidden;visible;hidden;hidden;hidden;" calcMode="linear" repeatCount="indefinite" />
<animate xlink:href="#a8" attributeName="visibility" begin="0s" dur="1.3s" values="hidden;hidden;hidden;hidden;hidden;hidden;hidden;visible;hidden;hidden;" calcMode="linear" repeatCount="indefinite" />
<animate xlink:href="#a9" attributeName="visibility" begin="0s" dur="1.3s" values="hidden;hidden;hidden;hidden;hidden;hidden;hidden;hidden;visible;hidden;" calcMode="linear" repeatCount="indefinite" />
<animate xlink:href="#a10" attributeName="visibility" begin="0s" dur="1.3s" values="hidden;hidden;hidden;hidden;hidden;hidden;hidden;hidden;hidden;visible;" calcMode="linear" repeatCount="indefinite" />
</svg>