SVG reversing animation - css
I'm still learning SMIL and one thing that bothers me is the no support for automatic reversed animations. So here's my test SVG I made quicky flor the purpose of testing SVG position animations.
In the simplest form, I want the animation to reverese back to its original starting position when reaching the end, like how the CSS animation alternate works.
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 124 82">
<defs>
<style>
.cls-1 {
fill: none;
stroke: #000;
stroke-miterlimit: 10;
stroke-width: 2px;
}
</style>
</defs>
<title>Untitled-5</title>
<line class="cls-1" x1="12" y1="70" x2="44" y2="12">
<animate class="anim_1" attributeName="y1" from="70" to="35" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="x2" from="44" to="59" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="y2" from="12" to="56" dur="2s" repeatCount="indefinite"/>
</line>
<line class="cls-1" x1="44" y1="12" x2="112" y2="45">
<animate class="anim_1" attributeName="x1" from="44" to="59" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="y1" from="12" to="56" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="x2" from="112" to="100" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="y2" from="45" to="12" dur="2s" repeatCount="indefinite"/>
</line>
<circle cx="12" cy="70" r="11" fill="white" stroke="black" stroke-width="2">
<animate class="anim_1" attributeName="cy" from="70" to="35" dur="2s" repeatCount="indefinite"/>
</circle>
<circle cx="44" cy="12" r="11" fill="white" stroke="black" stroke-width="2">
<animate class="anim_1" attributeName="cx" from="44" to="59" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="cy" from="12" to="56" dur="2s" repeatCount="indefinite"/>
</circle>
<circle cx="112" cy="45" r="11" fill="white" stroke="black" stroke-width="2">
<animate class="anim_1" attributeName="cx" from="112" to="100" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="cy" from="45" to="12" dur="2s" repeatCount="indefinite"/>
</circle>
</svg>
As you can see, the animation runs perfectly until it reaches the end, and just skips back to the start. Unfortunately, the way I'm implementing my larger SVG has no support for JS changing the <svg> element.
I know this question has been asked a few times already, Here for example. They all seem to cover only the <motionPath> element using keyPoints and keyTimes, if there's a way to accomplish this with my SVG using motion paths that'd be fine too, I'm just not sure how.
Thanks in advance for help!
Yes you are on the good path with keyTimes.
But what you need for your <animate> is the values attribute.
Basically, for each <animate>, I
added keyTimes = "0; .5; 1" so that we've got our 3 way points
converted from and to attributes to values="from;to;from"
changed the dur to make it twice longer.
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 124 82">
<defs>
<style>
.cls-1 {
fill: none;
stroke: #000;
stroke-miterlimit: 10;
stroke-width: 2px;
}
</style>
</defs>
<title>Untitled-5</title>
<line class="cls-1" x1="12" y1="70" x2="44" y2="12">
<animate class="anim_1" attributeName="y1" dur="4s" repeatCount="indefinite" keyTimes="0;0.5;1" values="70;35;70"></animate>
<animate class="anim_1" attributeName="x2" dur="4s" repeatCount="indefinite" keyTimes="0;0.5;1" values="44;59;44"></animate>
<animate class="anim_1" attributeName="y2" dur="4s" repeatCount="indefinite" keyTimes="0;0.5;1" values="12;56;12"></animate>
</line>
<line class="cls-1" x1="44" y1="12" x2="112" y2="45">
<animate class="anim_1" attributeName="x1" dur="4s" repeatCount="indefinite" keyTimes="0;0.5;1" values="44;59;44"></animate>
<animate class="anim_1" attributeName="y1" dur="4s" repeatCount="indefinite" keyTimes="0;0.5;1" values="12;56;12"></animate>
<animate class="anim_1" attributeName="x2" dur="4s" repeatCount="indefinite" keyTimes="0;0.5;1" values="112;100;112"></animate>
<animate class="anim_1" attributeName="y2" dur="4s" repeatCount="indefinite" keyTimes="0;0.5;1" values="45;12;45"></animate>
</line>
<circle cx="12" cy="70" r="11" fill="white" stroke="black" stroke-width="2">
<animate class="anim_1" attributeName="cy" dur="4s" repeatCount="indefinite" keyTimes="0;0.5;1" values="70;35;70"></animate>
</circle>
<circle cx="44" cy="12" r="11" fill="white" stroke="black" stroke-width="2">
<animate class="anim_1" attributeName="cx" dur="4s" repeatCount="indefinite" keyTimes="0;0.5;1" values="44;59;44"></animate>
<animate class="anim_1" attributeName="cy" dur="4s" repeatCount="indefinite" keyTimes="0;0.5;1" values="12;56;12"></animate>
</circle>
<circle cx="112" cy="45" r="11" fill="white" stroke="black" stroke-width="2">
<animate class="anim_1" attributeName="cx" dur="4s" repeatCount="indefinite" keyTimes="0;0.5;1" values="112;100;112"></animate>
<animate class="anim_1" attributeName="cy" dur="4s" repeatCount="indefinite" keyTimes="0;0.5;1" values="45;12;45"></animate>
</circle>
</svg>
And if you want the js I made :
document.querySelectorAll('animate').forEach(a => {
a.setAttribute('keyTimes', '0;0.5;1');
let f = a.getAttribute('from');
let t = a.getAttribute('to');
a.setAttribute('values', f + ';' + t + ';' + f)
a.removeAttribute('from');
a.removeAttribute('to');
a.setAttribute('dur', (parseFloat(a.getAttribute('dur')) * 2) + 's');
})
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 124 82">
<defs>
<style>
.cls-1 {
fill: none;
stroke: #000;
stroke-miterlimit: 10;
stroke-width: 2px;
}
</style>
</defs>
<title>Untitled-5</title>
<line class="cls-1" x1="12" y1="70" x2="44" y2="12">
<animate class="anim_1" attributeName="y1" from="70" to="35" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="x2" from="44" to="59" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="y2" from="12" to="56" dur="2s" repeatCount="indefinite"/>
</line>
<line class="cls-1" x1="44" y1="12" x2="112" y2="45">
<animate class="anim_1" attributeName="x1" from="44" to="59" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="y1" from="12" to="56" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="x2" from="112" to="100" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="y2" from="45" to="12" dur="2s" repeatCount="indefinite"/>
</line>
<circle cx="12" cy="70" r="11" fill="white" stroke="black" stroke-width="2">
<animate class="anim_1" attributeName="cy" from="70" to="35" dur="2s" repeatCount="indefinite"/>
</circle>
<circle cx="44" cy="12" r="11" fill="white" stroke="black" stroke-width="2">
<animate class="anim_1" attributeName="cx" from="44" to="59" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="cy" from="12" to="56" dur="2s" repeatCount="indefinite"/>
</circle>
<circle cx="112" cy="45" r="11" fill="white" stroke="black" stroke-width="2">
<animate class="anim_1" attributeName="cx" from="112" to="100" dur="2s" repeatCount="indefinite"/>
<animate class="anim_1" attributeName="cy" from="45" to="12" dur="2s" repeatCount="indefinite"/>
</circle>
</svg>
Related
Animate SVG Circles with Transform Origin
I'm trying to animate 3x Individual Circles within one SVG. I've got them to animate, but they have moved position into the top left corner. This happened when I added the following CSS: .payment svg * { transform-origin: center; /* or transform-origin: 50% */ transform-box: fill-box; } <div class="payment"> <svg width="689px" height="370px" viewBox="0 0 689 370" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <!-- Generator: Sketch 62 (91390) - https://sketch.com --> <title>Circles</title> <desc>Created with Sketch.</desc> <defs> <linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-1"> <stop stop-color="#454545" offset="0%"></stop> <stop stop-color="#FFFFFF" offset="100%"></stop> </linearGradient> </defs> <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="Artboard" stroke="url(#linearGradient-1)"> <g id="Circles" transform="translate(1.000000, 1.000000)"> <g id="mini" transform="translate(0.000000, 60.000000)" opacity="0.50042" stroke-dasharray="3" transform="rotate(360)"> <path d="M127,254 C197.140163,254 254,197.140163 254,127 C254,56.8598368 197.140163,0 127,0 C56.8598368,0 0,56.8598368 0,127 C0,197.140163 56.8598368,254 127,254 Z" id="Oval"></path> <animateTransform attributeName="transform" attributeType="XML" dur="15s" repeatCount="indefinite" type="rotate" values="0;360" calcMode="linear"></animateTransform> </g> <g id="small" transform="translate(135.000000, 30.000000)" opacity="0.5" stroke-dasharray="6,10" transform="rotate(360)"> <path d="M154,308 C239.051851,308 308,239.051851 308,154 C308,68.9481485 239.051851,0 154,0 C68.9481485,0 0,68.9481485 0,154 C0,239.051851 68.9481485,308 154,308 Z" id="Oval-Copy-3"></path> <animateTransform attributeName="transform" attributeType="XML" dur="25s" repeatCount="indefinite" type="rotate" values="0;360" calcMode="linear"></animateTransform> </g> <g id="large" transform="translate(319.000000, 0.000000)" opacity="0.5" stroke-dasharray="16,10" transform="rotate(360)"> <path d="M184,368 C285.620394,368 368,285.620394 368,184 C368,82.379606 285.620394,0 184,0 C82.379606,0 0,82.379606 0,184 C0,285.620394 82.379606,368 184,368 Z" id="Oval-Copy-4"></path> <animateTransform attributeName="transform" attributeType="XML" dur="35s" repeatCount="indefinite" type="rotate" values="0;360" calcMode="linear"></animateTransform> </g> </g> </g> </g> </svg> </div> But without the above CSS, they do not stay in the same position and rotate. Does anyone know how to keep them in the same position and rotate 360 without moving? <svg width="689px" height="370px" viewBox="0 0 689 370" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <!-- Generator: Sketch 62 (91390) - https://sketch.com --> <title>Circles</title> <desc>Created with Sketch.</desc> <defs> <linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-1"> <stop stop-color="#454545" offset="0%"></stop> <stop stop-color="#FFFFFF" offset="100%"></stop> </linearGradient> </defs> <g id="Page-1" stroke="none" stroke-width="1" fill="none" fill-rule="evenodd"> <g id="Artboard" stroke="url(#linearGradient-1)"> <g id="Circles" transform="translate(1.000000, 1.000000)"> <g id="mini" transform="translate(0.000000, 60.000000)" opacity="0.50042" stroke-dasharray="3" transform="rotate(360)"> <path d="M127,254 C197.140163,254 254,197.140163 254,127 C254,56.8598368 197.140163,0 127,0 C56.8598368,0 0,56.8598368 0,127 C0,197.140163 56.8598368,254 127,254 Z" id="Oval"></path> </g> <g id="small" transform="translate(135.000000, 30.000000)" opacity="0.5" stroke-dasharray="6,10" transform="rotate(360)"> <path d="M154,308 C239.051851,308 308,239.051851 308,154 C308,68.9481485 239.051851,0 154,0 C68.9481485,0 0,68.9481485 0,154 C0,239.051851 68.9481485,308 154,308 Z" id="Oval-Copy-3"></path> </g> <g id="large" transform="translate(319.000000, 0.000000)" opacity="0.5" stroke-dasharray="16,10" transform="rotate(360)"> <path d="M184,368 C285.620394,368 368,285.620394 368,184 C368,82.379606 285.620394,0 184,0 C82.379606,0 0,82.379606 0,184 C0,285.620394 82.379606,368 184,368 Z" id="Oval-Copy-4"></path> </g> </g> </g> </g> </svg>
main idea - rotation around origin(0,0) before translation: <svg viewBox="-200 -100 400 200" width=90vw> <defs> <linearGradient x1="50%" y1="0%" x2="50%" y2="100%" id="linearGradient-1"> <stop stop-color="#454545" offset="0%"></stop> <stop stop-color="#FFFFFF" offset="100%"></stop> </linearGradient> </defs> <g stroke-width="1" fill="none"> <g stroke="url(#linearGradient-1)"> <g opacity="0.5" stroke-dasharray="3" transform="translate(-100,0)" > <circle r="80" > <animateTransform attributeName="transform" attributeType="XML" dur="15s" repeatCount="indefinite" type="rotate" values="0;360" calcMode="linear"></animateTransform> </circle> </g> <g stroke-dasharray="6,10"> <circle r="90"> <animateTransform attributeName="transform" attributeType="XML" dur="25s" repeatCount="indefinite" type="rotate" values="0;360" calcMode="linear"></animateTransform> </circle> </g> <g opacity="0.5" stroke-dasharray="16,10" transform="translate(100,0)"> <circle r="100"> <animateTransform attributeName="transform" attributeType="XML" dur="35s" repeatCount="indefinite" type="rotate" values="0;360" calcMode="linear"></animateTransform> </circle> </g> </g> </g> </svg>
How to animate pattern items sequentially?
<svg viewbox="0 0 100 100"> <defs> <pattern id="dotted-pattern" viewbox="0,0,100,100" height="3.125%" width="3.125%"> <circle cx="50" cy="50" fill="#10446D" r="12"> <animate attributeName="opacity" values="0; 1" keyTimes="0; 1" dur="1s" begin="0s" repeatCount="1" fill="freeze" /> </circle> </pattern> <mask id="circle-mask" maskContentUnits="userSpaceOnUse" maskUnits="userSpaceOnUse"> <circle cx="50" cy="50" r="38.48" width="100" height="100" fill="white"></circle> </mask> </defs> <rect width="74" height="74" y="13" x="13" mask="url(#circle-mask)" fill="url(#dotted-pattern)"></rect> </svg> This way animation runs simultaneously for all pattern items. How to run this sequentially? Start next item animation if the previous one completed?
Instead of animating the circles of the pattern I would animate a radial gradient from white to black, and I would use this gradient to fill the mask circle like so: <svg viewbox="0 0 100 100"> <defs> <radialGradient id="rg" cx=".5" cy=".5" r="0.01"> <stop offset="0%" stop-color="white"></stop> <stop offset="100%" stop-color="black"></stop> <animate attributeName="r" values="0.01; 1" dur="3s" begin="0s" repeatCount="1" fill="freeze" /> </radialGradient> <pattern id="dotted-pattern" viewbox="0,0,100,100" height="3.125%" width="3.125%"> <circle cx="50" cy="50" fill="#10446D" r="12"/> </pattern> <mask id="circle-mask" maskContentUnits="userSpaceOnUse" maskUnits="userSpaceOnUse"> <circle id="kk" cx="50" cy="50" r="38.48" width="100" height="100" fill="url(#rg)"> </circle> </mask> </defs> <rect width="74" height="74" y="13" x="13" mask="url(#circle-mask)" fill="url(#dotted-pattern)"></rect> </svg> SECOND Solution You may fill the mask circle with white and animate the radius like so: <svg viewbox="0 0 100 100"> <defs> <pattern id="dotted-pattern" viewbox="0,0,100,100" height="3.125%" width="3.125%"> <circle cx="50" cy="50" fill="#10446D" r="12"/> </pattern> <mask id="circle-mask" maskContentUnits="userSpaceOnUse" maskUnits="userSpaceOnUse"> <circle id="kk" cx="50" cy="50" r="38.48" width="100" height="100" fill="white"> <animate attributeName="r" values="0.01; 38.48" dur="3s" begin="0s" repeatCount="1" fill="freeze" /> </circle> </mask> </defs> <rect width="74" height="74" y="13" x="13" mask="url(#circle-mask)" fill="url(#dotted-pattern)"></rect> </svg>
SVG <path/> <animation> not working
This following svg code plays the first part of animation but rest 3 wont. Its on a wordpress website, is that has something to do with it? If i open the svg from computer in a browser it works fine. Thanks in advance <g> <path d="M352,418.9c0,30.3-0.1,60.6,0.1,91c0,5.8-2.1,9.1-7.2,11c-26.7,10-53.3,20-80,29.8c-7.9,2.9-17.9-4.7-17.9-13.2 c-0.1-40,0.2-80-0.4-119.9c-0.4-24.6-0.4-49.3-0.7-73.9c-0.1-7.3,0.7-8.3,7.7-9.9c27.1-6.2,54.2-12.4,81.3-18.6 c10.1-2.3,17.2,3.5,17.2,13.8C352,358.9,352,388.9,352,418.9z" fill="url(#imgpattern)" id="core_type"/> <animate xlink:href="#core_type" attributeName="d" attributeType="XML" from="M352,418.9c0,30.3-0.1,60.6,0.1,91c0,5.8-2.1,9.1-7.2,11c-26.7,10-53.3,20-80,29.8c-7.9,2.9-17.9-4.7-17.9-13.2 c-0.1-40,0.2-80-0.4-119.9c-0.4-24.6-0.4-49.3-0.7-73.9c-0.1-7.3,0.7-8.3,7.7-9.9c27.1-6.2,54.2-12.4,81.3-18.6 c10.1-2.3,17.2,3.5,17.2,13.8C352,358.9,352,388.9,352,418.9z" to="M202,350.9c0,30.3-0.1,60.6,0.1,91c0,5.8-2.1,9.1-7.2,11c-26.7,10-53.3,20-80,29.8c-7.9,2.9-17.9-4.7-17.9-13.2 c-0.1-40,0.2-80-0.4-119.9c-0.4-24.6-0.4-49.3-0.7-73.9c-0.1-7.3,0.7-8.3,7.7-9.9c27.1-6.2,54.2-12.4,81.3-18.6 c10.1-2.3,17.2,3.5,17.2,13.8C352,358.9,352,388.9,352,418.9z" dur="2s" begin="0s; animation4.end" fill="freeze" id="animation" /> <animate xlink:href="#core_type" attributeName="d" attributeType="XML" from="M202,350.9c0,30.3-0.1,60.6,0.1,91c0,5.8-2.1,9.1-7.2,11c-26.7,10-53.3,20-80,29.8c-7.9,2.9-17.9-4.7-17.9-13.2 c-0.1-40,0.2-80-0.4-119.9c-0.4-24.6-0.4-49.3-0.7-73.9c-0.1-7.3,0.7-8.3,7.7-9.9c27.1-6.2,54.2-12.4,81.3-18.6 c10.1-2.3,17.2,3.5,17.2,13.8C352,358.9,352,388.9,352,418.9z" to="M202,350.9c0,30.3-0.1,60.6,0.1,91c0,5.8-2.1,9.1-7.2,11c-26.7,10-53.3,20-80,29.8c-7.9,2.9-17.9-4.7-17.9-13.2 c-0.1-40,0.2-80-0.4-119.9c-0.4-24.6-0.4-49.3-0.7-73.9c-0.1-7.3,0.7-8.3,7.7-9.9c27.1-6.2,54.2-12.4,81.3-18.6 c10.1-2.3,17.2,3.5,17.2,13.8C352,358.9,352,388.9,352,418.9z" dur="2s" begin="animation.end" fill="freeze" id="animation2" /> <animate xlink:href="#core_type" attributeName="d" attributeType="XML" to="M352,418.9c0,30.3-0.1,60.6,0.1,91c0,5.8-2.1,9.1-7.2,11c-26.7,10-53.3,20-80,29.8c-7.9,2.9-17.9-4.7-17.9-13.2 c-0.1-40,0.2-80-0.4-119.9c-0.4-24.6-0.4-49.3-0.7-73.9c-0.1-7.3,0.7-8.3,7.7-9.9c27.1-6.2,54.2-12.4,81.3-18.6 c10.1-2.3,17.2,3.5,17.2,13.8C352,358.9,352,388.9,352,418.9z" from="M202,350.9c0,30.3-0.1,60.6,0.1,91c0,5.8-2.1,9.1-7.2,11c-26.7,10-53.3,20-80,29.8c-7.9,2.9-17.9-4.7-17.9-13.2 c-0.1-40,0.2-80-0.4-119.9c-0.4-24.6-0.4-49.3-0.7-73.9c-0.1-7.3,0.7-8.3,7.7-9.9c27.1-6.2,54.2-12.4,81.3-18.6 c10.1-2.3,17.2,3.5,17.2,13.8C352,358.9,352,388.9,352,418.9z" dur="2s" begin="animation2.end" fill="freeze" id="animation3" /> <animate xlink:href="#core_type" attributeName="d" attributeType="XML" from="M352,418.9c0,30.3-0.1,60.6,0.1,91c0,5.8-2.1,9.1-7.2,11c-26.7,10-53.3,20-80,29.8c-7.9,2.9-17.9-4.7-17.9-13.2 c-0.1-40,0.2-80-0.4-119.9c-0.4-24.6-0.4-49.3-0.7-73.9c-0.1-7.3,0.7-8.3,7.7-9.9c27.1-6.2,54.2-12.4,81.3-18.6 c10.1-2.3,17.2,3.5,17.2,13.8C352,358.9,352,388.9,352,418.9z" to="M352,418.9c0,30.3-0.1,60.6,0.1,91c0,5.8-2.1,9.1-7.2,11c-26.7,10-53.3,20-80,29.8c-7.9,2.9-17.9-4.7-17.9-13.2 c-0.1-40,0.2-80-0.4-119.9c-0.4-24.6-0.4-49.3-0.7-73.9c-0.1-7.3,0.7-8.3,7.7-9.9c27.1-6.2,54.2-12.4,81.3-18.6 c10.1-2.3,17.2,3.5,17.2,13.8C352,358.9,352,388.9,352,418.9z" dur="2s" begin="animation3.end" fill="freeze" id="animation4" /> </g>
Set svg animate's attribute from css
I have an SVG animation, I want to set animate tags attribute from and to using css. like: animate{ from: #f7f7f7; to: #33d424; } Is this possible, how can I do that ? Here is my SVG code: <svg width='100px' height='100px' xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100" preserveAspectRatio="xMidYMid" class="uil-squares"> <rect x="0" y="0" width="100" height="100" fill="none" class="bk"></rect> <rect x="15" y="15" width="20" height="20" fill="#f7f7f7" class="sq"> <animate attributeName="fill" from="#f7f7f7" to="#33d424" repeatCount="indefinite" dur="1s" begin="0.0s" values="#33d424;#33d424;#f7f7f7;#f7f7f7" keyTimes="0;0.1;0.2;1"></animate> </rect> <rect x="40" y="15" width="20" height="20" fill="#f7f7f7" class="sq"> <animate attributeName="fill" from="#f7f7f7" to="#33d424" repeatCount="indefinite" dur="1s" begin="0.125s" values="#33d424;#33d424;#f7f7f7;#f7f7f7" keyTimes="0;0.1;0.2;1"></animate> </rect> <rect x="65" y="15" width="20" height="20" fill="#f7f7f7" class="sq"> <animate attributeName="fill" from="#f7f7f7" to="#33d424" repeatCount="indefinite" dur="1s" begin="0.25s" values="#33d424;#33d424;#f7f7f7;#f7f7f7" keyTimes="0;0.1;0.2;1"></animate> </rect> <rect x="15" y="40" width="20" height="20" fill="#f7f7f7" class="sq"> <animate attributeName="fill" from="#f7f7f7" to="#33d424" repeatCount="indefinite" dur="1s" begin="0.875s" values="#33d424;#33d424;#f7f7f7;#f7f7f7" keyTimes="0;0.1;0.2;1"></animate> </rect> <rect x="65" y="40" width="20" height="20" fill="#f7f7f7" class="sq"> <animate attributeName="fill" from="#f7f7f7" to="#33d424" repeatCount="indefinite" dur="1s" begin="0.375" values="#33d424;#33d424;#f7f7f7;#f7f7f7" keyTimes="0;0.1;0.2;1"></animate> </rect> <rect x="15" y="65" width="20" height="20" fill="#f7f7f7" class="sq"> <animate attributeName="fill" from="#f7f7f7" to="#33d424" repeatCount="indefinite" dur="1s" begin="0.75s" values="#33d424;#33d424;#f7f7f7;#f7f7f7" keyTimes="0;0.1;0.2;1"></animate> </rect> <rect x="40" y="65" width="20" height="20" fill="#f7f7f7" class="sq"> <animate attributeName="fill" from="#f7f7f7" to="#33d424" repeatCount="indefinite" dur="1s" begin="0.625s" values="#33d424;#33d424;#f7f7f7;#f7f7f7" keyTimes="0;0.1;0.2;1"></animate> </rect> <rect x="65" y="65" width="20" height="20" fill="#f7f7f7" class="sq"> <animate attributeName="fill" from="#f7f7f7" to="#33d424" repeatCount="indefinite" dur="1s" begin="0.5s" values="#33d424;#33d424;#f7f7f7;#f7f7f7" keyTimes="0;0.1;0.2;1"></animate> </rect> </svg>
You would have to use CSS animations instead of SVG ones. Something like this: http://jsfiddle.net/scarl3tt/g2frngcn/ #keyframes animate { 0% { fill: #f7f7f7; } 6.25% { fill: #33d424; } 12.5% { fill: #f7f7f7; } } You also need to delay each element's animation to make them run in sequence. I wrote this in pure CSS because I'm not sure how familiar you are with SASS/LESS, but using a preprocessor and an autoprefixer makes this kind of thing a lot easier.
Rotate dashes of SVG stroke-dasharray
I'm looking to animate the rotation of individual dashes of an SVG stroke-dasharray, does anyone know how, given it is possible? I realize I can rotate the entire object of SVG element with CSS' transform:rotate(), but is there any way I can rotate individual dashes? I also realize I could recreate it all using individual elements and rotate those, but that's not what I'm looking to do for performance and brevity reasons Here's a demo if you're looking to have one. I'd like the squares to stay upright in their place, not rotating as they go around in a circular path. I'm looking to recreate this gif P.S. I know the circles aren't perfectly aligned, I asked about that before
I made sample. http://jsdo.it/defghi1977/sQOc Robert Longson's "markers" approach is very nice! Thank you! <?xml version="1.0" standalone="no"?> <svg width="400px" height="400px" viewBox="-200 -200 400 400" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" style="background-color:black;"> <defs> <rect id="markerShape" x="-1" y="-1" width="2" height="2" fill="yellow"> <animateTransform attributeName="transform" type="rotate" to="360,0,0" begin="0s" dur="30s" repeatCount="indefinite"/> </rect> <marker id="marker1" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1"> <use xlink:href="#markerShape" transform="scale(0.02,0.02)"/><!--NOTE: =1/50--> <animate attributeName="orient" from="0" to="-30" begin="0s" dur="5s" repeatCount="indefinite"/> </marker> <marker id="marker2" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1"> <use xlink:href="#markerShape" transform="scale(0.01428,0.01428)"/><!--NOTE: =1/70--> <animate attributeName="orient" from="0" to="-60" begin="0s" dur="5s" repeatCount="indefinite"/> </marker> <marker id="marker3" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1"> <use xlink:href="#markerShape" transform="scale(0.01111,0.01111)"/><!--NOTE: =1/90--> <animate attributeName="orient" from="0" to="-90" begin="0s" dur="5s" repeatCount="indefinite"/> </marker> <marker id="marker4" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1"> <use xlink:href="#markerShape" transform="scale(0.00909,0.00909)"/><!--NOTE: =1/110--> <animate attributeName="orient" from="0" to="-120" begin="0s" dur="5s" repeatCount="indefinite"/> </marker> <marker id="marker5" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1"> <use xlink:href="#markerShape" transform="scale(0.007692,0.007692)"/><!--NOTE: =1/130--> <animate attributeName="orient" from="0" to="-150" begin="0s" dur="5s" repeatCount="indefinite"/> </marker> <marker id="marker6" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1"> <use xlink:href="#markerShape" transform="scale(0.00666,0.00666)"/><!--NOTE: =1/150--> <animate attributeName="orient" from="0" to="-180" begin="0s" dur="5s" repeatCount="indefinite"/> </marker> <marker id="marker7" markerUnits="strokeWidth" viewBox="-1 -1 2 2" overflow="visible" markerWidth="1" markerHeight="1"> <use xlink:href="#markerShape" transform="scale(0.00588,0.00588)"/><!--NOTE: =1/180--> <animate attributeName="orient" from="0" to="-210" begin="0s" dur="5s" repeatCount="indefinite"/> </marker> <polygon id="basicShape" fill="none" points=" 0,1 0.5,0.86603 0.86603,0.5 1,0 0.86603,-0.5 0.5,-0.86603 0,-1 -0.5,-0.86603 -0.86603,-0.5 -1,0 -0.86603,0.5 -0.5,0.86603" /> </defs> <g> <use xlink:href="#basicShape" transform="scale(50,50)" stroke-width="14" marker-mid="url(#marker1)" marker-start="url(#marker1)"/> <animateTransform attributeName="transform" type="rotate" to="30,0,0" begin="0s" dur="5s" repeatCount="indefinite"/> </g> <g> <use xlink:href="#basicShape" transform="scale(70,70)" stroke-width="15" marker-mid="url(#marker2)" marker-start="url(#marker2)"/> <animateTransform attributeName="transform" type="rotate" to="60,0,0" begin="0s" dur="5s" repeatCount="indefinite"/> </g> <g> <use xlink:href="#basicShape" transform="scale(90,90)" stroke-width="16" marker-mid="url(#marker3)" marker-start="url(#marker3)"/> <animateTransform attributeName="transform" type="rotate" to="90,0,0" begin="0s" dur="5s" repeatCount="indefinite"/> </g> <g> <use xlink:href="#basicShape" transform="scale(110,110)" stroke-width="17" marker-mid="url(#marker4)" marker-start="url(#marker4)"/> <animateTransform attributeName="transform" type="rotate" to="120,0,0" begin="0s" dur="5s" repeatCount="indefinite"/> </g> <g> <use xlink:href="#basicShape" transform="scale(130,130)" stroke-width="18" marker-mid="url(#marker5)" marker-start="url(#marker5)"/> <animateTransform attributeName="transform" type="rotate" to="150,0,0" begin="0s" dur="5s" repeatCount="indefinite"/> </g> <g> <use xlink:href="#basicShape" transform="scale(150,150)" stroke-width="19" marker-mid="url(#marker6)" marker-start="url(#marker6)"/> <animateTransform attributeName="transform" type="rotate" to="180,0,0" begin="0s" dur="5s" repeatCount="indefinite"/> </g> <g> <use xlink:href="#basicShape" transform="scale(170,170)" stroke-width="21" marker-mid="url(#marker7)" marker-start="url(#marker7)"/> <animateTransform attributeName="transform" type="rotate" to="210,0,0" begin="0s" dur="5s" repeatCount="indefinite"/> </g> </svg>
stroke-dasharray is the wrong approach as you can't affect the dash rotation. A better approach would be to use square markers on a path such that each path vertex has a marker with a fixed orient attribute. The path itself could be transparent so just the markers are visible.