simplify this css svg animation - html

I'm working on this to have the rect to change colors. Each rect will change on a 0.1s delay.
Let's say I want to have more rectangles or path, how can I simplify the code? I think it could be simplified using scss but what about using CSS? is there a smarter way to do so rather than the way I have done?
#svg rect:nth-child(1) {
animation: ani 1.8s linear infinite;
animation-delay: 0.1s;
}
#svg rect:nth-child(1):hover {
animation-play-state: paused;
}
#svg rect:nth-child(2) {
animation: ani 1.8s linear infinite;
animation-delay: 0.2s;
}
#svg rect:nth-child(2):hover {
animation-play-state: paused;
}
#svg rect:nth-child(3) {
animation: ani 1.8s linear infinite;
animation-delay: 0.3s;
}
#svg rect:nth-child(3):hover {
animation-play-state: paused;
}
#svg rect:nth-child(4) {
animation: ani 1.8s linear infinite;
animation-delay: 0.4s;
}
#svg rect:nth-child(4):hover {
animation-play-state: paused;
}
#svg rect:nth-child(5) {
animation: ani 1.8s linear infinite;
animation-delay: 0.5s;
}
#svg rect:nth-child(5):hover {
animation-play-state: paused;
}
#keyframes ani {
0% {
fill: #0057B8;
}
20% {
fill: #F11E4A;
}
40% {
fill: #F8A527;
}
60% {
fill: #266D7F;
}
80% {
fill: #82A;
}
100% {
fill: #0057B8;
}
}
<svg id="svg" width="401" height="275" viewBox="0 0 401 275" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="401" height="275" fill="white"/>
<rect x="50" y="91" width="57" height="57" fill="#C4C4C4"/>
<rect x="118" y="91" width="57" height="57" fill="#C4C4C4"/>
<rect x="186" y="91" width="57" height="57" fill="#C4C4C4"/>
<rect x="254" y="91" width="57" height="57" fill="#C4C4C4"/>
</svg>

For the :hover and base rect animation duplication, they can each be refactored into their own block.
#svg rect {
--animation-delay: 0.1s;
animation: ani 1.8s linear infinite var(--animation-delay);
}
#svg rect:hover {
animation-play-state: paused;
}
I would store the animation delay in a custom property and add it to the lone animation call.
#svg rect {
--animation-delay: 0.1s;
animation: ani 1.8s linear infinite var(--animation-delay);
}
Now you can override the delay later when necessary, such as:
#svg rect:nth-child(3) { --animation-delay: 0.2s; }
The delay will automatically update for that child's animation.
Here's the complete code:
#svg rect {
--animation-delay: 0.1s;
animation: ani 1.8s linear infinite var(--animation-delay);
}
#svg rect:hover {
animation-play-state: paused;
}
<!-- No way to shorten this in pure CSS 😠 -->
#svg rect:nth-child(2) { --animation-delay: 0.2s; }
#svg rect:nth-child(3) { --animation-delay: 0.3s; }
#svg rect:nth-child(4) { --animation-delay: 0.4s; }
#svg rect:nth-child(5) { --animation-delay: 0.5s; }
#keyframes ani {
0% {
fill: #0057B8;
}
20% {
fill: #F11E4A;
}
40% {
fill: #F8A527;
}
60% {
fill: #266D7F;
}
80% {
fill: #82A;
}
100% {
fill: #0057B8;
}
}
<svg id="svg" width="401" height="275" viewBox="0 0 401 275" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="401" height="275" fill="white" />
<rect x="50" y="91" width="57" height="57" fill="#C4C4C4" />
<rect x="118" y="91" width="57" height="57" fill="#C4C4C4" />
<rect x="186" y="91" width="57" height="57" fill="#C4C4C4" />
<rect x="254" y="91" width="57" height="57" fill="#C4C4C4" />
</svg>
jsFiddle

All your :hover effects are the same, and so are your animation properties so you can simplify those to one rule each:
#svg rect {
animation: ani 1.8s linear infinite;
}
#svg rect:hover {
animation-play-state: paused;
}
that would already reduce the lines a lot, for the animation delays themselves your method is ok.

If you are intrested in a CSS solution you can do something like below. It's a bit different animation but you can easily scale it by keeping the same code.
The trick is to animate the same gradient for all the boxes to simulate the color changes. Note how I made the pseudo element relative to the .box not the child elements to have the same layer
.box {
display:inline-flex;
margin:5px;
padding:50px 20px;
position:relative;
background:right/800% 100%;
background-image:linear-gradient(to left,#0057B8,#F11E4A,#F8A527,#266D7F,#82A,#0057B8);
animation: ani 1.8s linear infinite;
}
.box > div {
margin:5px;
height:55px;
width:55px;
background-image:inherit;
-webkit-mask: linear-gradient(#fff,#fff);
mask: linear-gradient(#fff,#fff);
}
.box > div:before {
content:"";
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
background: right/1000% 100%;
background-image:inherit;
animation: ani 2s linear infinite;
}
.box > div:hover:before {
animation-play-state:paused;
}
#keyframes ani {
100% {
background-position:left;
}
}
<div class="box">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>
<br>
<div class="box">
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
<div></div>
</div>

Related

Circles "waves" animations with CSS keyframes

I'm trying to animate circles to achieve an infinite effect of colliding waves.
I laid the base but I can't make the order of the animations smooth and linear.
Codepen available here.
<div class="circles-container"
<!-- 1er circle -->
<svg width="1280" height="1280" xmlns="http://www.w3.org/2000/svg" style="z-index: 1;">
<path class="circle-1" d="M0 0h640c0 353.466-286.534 640-640 640V0Z" fill="currentColor" fill-rule="evenodd" />
</svg>
<!-- 2eme circle -->
<svg width="1280" height="1280" xmlns="http://www.w3.org/2000/svg" style="z-index: 2;">
<path class="circle-2" d="M0 0h640c0 353.466-286.534 640-640 640V0Z" fill="currentColor" fill-rule="evenodd" />
</svg>
<!-- 3eme circle -->
<svg width="1280" height="1280" xmlns="http://www.w3.org/2000/svg" style="z-index: 3;">
<path class="circle-3" d="M0 0h640c0 353.466-286.534 640-640 640V0Z" fill="currentColor" fill-rule="evenodd" />
</svg>
</div>
.circles-container { position: relative; }
.circles-container svg {
position: absolute;
top: 0;
left: 0;
}
.circle-1 {
animation: scaleCircle 7.5s ease-in-out infinite;
transform: scale(0);
transition: all 2s ease-in-out;
color: #1D1D28;
}
.circle-2 {
animation: scaleCircle 5s ease-in-out infinite 2.5s;
transform: scale(0);
transition: all 2s ease-in-out;
color: #420DC4;
}
.circle-3 {
animation: scaleCircle 5s ease-in-out infinite;
transform: scale(0);
transition: all 2s ease-in-out;
color: #1D1D28;
}
#keyframes scaleCircle {
0% {
transform: scale(0);
}
100% {
transform: scale(2);
}
}
Here is the scenario:
When loading, a first blue circle is displayed.
A first black circle grows until it crushes the blue circle
at 50% of step's 1 animation, a new blue circle is displayed and enlarged until it overwrites the black circle created during step 1
back to step 1
In my render, you can see that the circles are showing but some are hiding too soon, etc. The circles should display one after the other in a linear fashion.
Is it possible to do this in full CSS with keyframes ?
Not sure if this is exactly what you are going for but maybe you can tinker with it.
So with 4 circles you can animate the scale basically the way you have it. And then for their svg container, you animate the z-index so whenever a wave starts it gets its highest z-index and then it deceases before the next wave starts.
<div class="circles-container">
<!-- 1er cercle -->
<svg class="circle-parent-1" width="1280" height="1280" xmlns="http://www.w3.org/2000/svg">
<path class="circle-1" d="M0 0h640c0 353.466-286.534 640-640 640V0Z" fill="currentColor" fill-rule="evenodd" />
</svg>
<!-- 2eme cercle -->
<svg class="circle-parent-2" width="1280" height="1280" xmlns="http://www.w3.org/2000/svg" >
<path class="circle-2" d="M0 0h640c0 353.466-286.534 640-640 640V0Z" fill="currentColor" fill-rule="evenodd" />
</svg>
<svg class="circle-parent-3" width="1280" height="1280" xmlns="http://www.w3.org/2000/svg" >
<path class="circle-3" d="M0 0h640c0 353.466-286.534 640-640 640V0Z" fill="currentColor" fill-rule="evenodd" />
</svg>
<svg class="circle-parent-4" width="1280" height="1280" xmlns="http://www.w3.org/2000/svg" >
<path class="circle-4" d="M0 0h640c0 353.466-286.534 640-640 640V0Z" fill="currentColor" fill-rule="evenodd" />
</svg>
body {
margin: 0;
padding: 0;
}
.circles-container { position: relative; }
.circles-container svg {
position: absolute;
top: 0;
left: 0;
}
.circle-parent-1 {
animation: zIndexCircle 8s ease-in-out infinite;
animation-delay: 0s;
}
.circle-parent-2 {
animation: zIndexCircle 8s ease-in-out infinite;
animation-delay: 2s;
}
.circle-parent-3 {
animation: zIndexCircle 8s ease-in-out infinite;
animation-delay: 4s;
}
.circle-parent-3 {
animation: zIndexCircle 8s ease-in-out infinite;
animation-delay: 4s;
}
.circle-parent-4 {
animation: zIndexCircle 8s ease-in-out infinite;
animation-delay: 6s;
}
.circle-1 {
animation: scaleCircle 8s ease-in-out infinite;
animation-delay:0s;
transform: scale(0);
color: #1D1D28;
}
.circle-2 {
animation: scaleCircle 8s ease-in-out infinite;
animation-delay:2s;
transform: scale(0);
color: #420DC4;
}
.circle-3 {
animation: scaleCircle 8s ease-in-out infinite;
animation-delay:4s;
transform: scale(0);
color: #1D1D28;
}
.circle-4 {
animation: scaleCircle 8s ease-in-out infinite;
animation-delay:6s;
transform: scale(0);
color: #420DC4;
}
#keyframes zIndexCircle {
0% {
z-index:5;
}
25% {
z-index: 4;
}
50% {
z-index:3;
}
75% {
z-index:2;
}
100% {
z-index:1;
}
}
#keyframes scaleCircle {
0% {
transform: scale(0);
}
75% {
transform: scale(2);
}
100% {
transform: scale(2);
}
}
https://codepen.io/todilo-the-vuer/pen/XWEmdXL

nth-child(an+b):hover does not work with CSS animation?

How to get the rect to change colour when hover?
I tried #svg rect:nth-child(an+b):hover syntax and it does not work.
I tried removing the animation-play-state:paused; and it does not work.
I tried using background: instead of fill:and it does not work.
#svg rect {
--animation-delay: 0.1s;
animation: ani 1.8s linear infinite var(--animation-delay);
}
#svg rect:hover {
animation-play-state: paused; /*/ Removing this does not work /*/
fill:#000; /*/ This is not working /*/
}
#svg rect:nth-child(2) { --animation-delay: 0.2s; }
#svg rect:nth-child(3) { --animation-delay: 0.3s; }
#svg rect:nth-child(4) { --animation-delay: 0.4s; }
#svg rect:nth-child(5) { --animation-delay: 0.5s; }
#svg rect:nth-child(2):hover { fill:#000; } /*/ This is not working too /*/
#svg rect:nth-child(3):hover { background:#fff; } /*/ This is not working too /*/
#keyframes ani {
0% {
fill: #0057B8;
}
20% {
fill: #F11E4A;
}
40% {
fill: #F8A527;
}
60% {
fill: #266D7F;
}
80% {
fill: #82A;
}
100% {
fill: #0057B8;
}
}
<svg id="svg" width="401" height="275" viewBox="0 0 401 275" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect width="401" height="275" fill="white"/>
<rect x="50" y="91" width="57" height="57" fill="#C4C4C4"/>
<rect x="118" y="91" width="57" height="57" fill="#C4C4C4"/>
<rect x="186" y="91" width="57" height="57" fill="#C4C4C4"/>
<rect x="254" y="91" width="57" height="57" fill="#C4C4C4"/>
</svg>
You must remove the animation and not only paused it to change fill on hover.
Therefore, you must replace
#svg rect:hover {
animation-play-state: paused;
fill:#000;
}
by
#svg rect:hover {
animation: none;
fill:#000;
}

How to animate a SVG with CSS?

I try to animate a SVG with CSS, but it wouldn't work as I thought.
First I create an animation for text DIV's-> that works fine. Then I use the same animation for the SVG path and here the automation runs complete different as for the text. Is it a bug? Or is it the wrong way to animate SVG?
svg {
border: solid 1px;
}
.deckel {
animation: ani1 5s;
animation-iteration-count: infinite;
}
.tank {
animation: ani2 5s;
animation-iteration-count: infinite;
}
.wo {
animation: ani3 5s;
animation-iteration-count: infinite;
}
.wm {
animation: ani4 5s;
animation-iteration-count: infinite;
}
.wu {
animation: ani5 5s;
animation-iteration-count: infinite;
}
#keyframes ani1 {
0% {
opacity: 0;
}
16% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes ani2 {
0% {
opacity: 0;
}
33% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes ani3 {
0% {
opacity: 0;
}
50% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes ani4 {
0% {
opacity: 0;
}
67% {
opacity: 0;
}
100% {
opacity: 1;
}
}
#keyframes ani5 {
0% {
opacity: 0;
}
83% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<div class="deckel">
Text1
</div>
<div class="tank">
Text2
</div>
<div class="wo">
Text3
</div>
<div class="wm">
Text4
</div>
<div class="wu">
Text5
</div>
<svg width="300" height="300">
<rect class="deckel" x="50" y="0" width="50" height="50" style="fill:blue;stroke:black;stroke-width:5;" />
<rect class="tank" x="50" y="50" width="50" height="50" style="fill:blue;stroke:black;stroke-width:5;" />
<rect class="wo" x="50" y="100" width="50" height="50" style="fill:blue;stroke:black;stroke-width:5;" />
<rect class="wm" x="50" y="150" width="50" height="50" style="fill:blue;stroke:black;stroke-width:5;" />
<rect class="wu" x="50" y="200" width="50" height="50" style="fill:blue;stroke:black;stroke-width:5;" />
</svg>
Thanks for your help!

SVG and keyframes not drawing letters fully

When playing around with some SVG animation, i ran into a strange artifact. When rendering keystroke-dashoffset animations in Chrome (haven't tested any other browsers) stops before they are finished, see below. In this case it is the S and M.
The lines also seem to retract a bit in the beginning. How do i fix this so that the letters render fully?
I use OSX El Capitan and Chrome v.51.0.2704.84.
Here is the code (not written by me):
text {
font-family: sans-serif;
stroke-dasharray: 100%;
stroke-dashoffset: 100%;
-webkit-animation: draw 8s forwards;
-moz-animation: draw 8s forwards;
-o-animation: draw 8s forwards;
-ms-animation: draw 8s forwards;
animation: draw 8s forwards;
}
#-webkit-keyframes draw {
100% {
stroke-dashoffset: 0;
}
}
#-moz-keyframes draw {
100% {
stroke-dashoffset: 0;
}
}
#-o-keyframes draw {
100% {
stroke-dashoffset: 0;
}
}
#-ms-keyframes draw {
100% {
stroke-dashoffset: 0;
}
}
#keyframes draw {
100% {
stroke-dashoffset: 0;
}
}
<svg width="500" height="150">
<text x="100" y="80" fill="none" stroke="black" stroke-width="1" font-size="50">Some text</text>
</svg>
The problem lies in the stroke-dasharray property in CSS. Setting this to a value larger than 100% (125% is enough for most fonts) will draw the letters correctly. This will cause the letters to already be drawn when the animation starts, so i set the stroke-dashoffset property to 125%, too.
body {
background:black;
}
text {
font-family: initial;
stroke-dasharray: 125%;
stroke-dashoffset: 125%;
-webkit-animation: draw 5s ease-in-out forwards;
-moz-animation: draw 5s ease-in-out forwards;
-o-animation: draw 5s ease-in-out forwards;
-ms-animation: draw 5s ease-in-out forwards;
animation: draw 5s ease-in-out forwards;
}
#-webkit-keyframes draw {
100% {
stroke-dashoffset: 0;
}
}
#-moz-keyframes draw {
100% {
stroke-dashoffset: 0;
}
}
#-o-keyframes draw {
100% {
stroke-dashoffset: 0;
}
}
#-ms-keyframes draw {
100% {
stroke-dashoffset: 0;
}
}
#keyframes draw {
100% {
stroke-dashoffset: 0;
}
}
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Open+Sans" />
<svg width="500" height="150">
<text x="100" y="80" fill="none" stroke="white" stroke-width="1" font-size="50">Some text</text>
</svg>

SVG width attribute css animation in firefox

SVG width attribute css animation not working in Firefox but in chrome it working perfectly. Please check the below snippet demo.
Does any wrong in my codes? Is there a way to apply the animation over the attribute width?
svg {
display: inline-block;
}
#-moz-keyframes glareAnim1 {
0% {
width: 0;
}
50% {
width: 10px;
}
100% {
width: 0;
}
}
#-webkit-keyframes glareAnim1 {
0% {
width: 0;
}
50% {
width: 10px;
}
100% {
width: 0;
}
}
#keyframes glareAnim1 {
0% {
width: 0;
}
50% {
width: 10px;
}
100% {
width: 0;
}
}
.glare-top {
-moz-animation: glareAnim1 2s linear infinite;
-webkit-animation: glareAnim1 2s linear infinite;
animation: glareAnim1 2s linear infinite;
}
#-moz-keyframes glareAnim2 {
0% {
width: 10px;
}
50% {
width: 0;
}
100% {
width: 10px;
}
}
#-webkit-keyframes glareAnim2 {
0% {
width: 10px;
}
50% {
width: 0;
}
100% {
width: 10px;
}
}
#keyframes glareAnim2 {
0% {
width: 10px;
}
50% {
width: 0;
}
100% {
width: 10px;
}
}
.glare-bottom {
-moz-animation: glareAnim2 2s linear infinite;
-webkit-animation: glareAnim2 2s linear infinite;
animation: glareAnim2 2s linear infinite;
}
#-moz-keyframes translateDoor {
0% {
-moz-transform: translate(-1px, 0);
transform: translate(-1px, 0);
opacity: 1;
width: 1px;
height: 6px;
}
15% {
width: 4px;
}
50% {
-moz-transform: translate(16px, 0);
transform: translate(16px, 0);
opacity: 1;
width: 2px;
}
51% {
opacity: 0;
}
100% {
-moz-transform: translateX(-10px);
transform: translateX(-10px);
opacity: 0;
}
}
#-webkit-keyframes translateDoor {
0% {
-webkit-transform: translate(-1px, 0);
transform: translate(-1px, 0);
opacity: 1;
width: 1px;
height: 6px;
}
15% {
width: 4px;
}
50% {
-webkit-transform: translate(16px, 0);
transform: translate(16px, 0);
opacity: 1;
width: 2px;
}
51% {
opacity: 0;
}
100% {
-webkit-transform: translateX(-10px);
transform: translateX(-10px);
opacity: 0;
}
}
#keyframes translateDoor {
0% {
-moz-transform: translate(-1px, 0);
-ms-transform: translate(-1px, 0);
-webkit-transform: translate(-1px, 0);
transform: translate(-1px, 0);
opacity: 1;
width: 1px;
height: 6px;
}
15% {
width: 4px;
}
50% {
-moz-transform: translate(16px, 0);
-ms-transform: translate(16px, 0);
-webkit-transform: translate(16px, 0);
transform: translate(16px, 0);
opacity: 1;
width: 2px;
}
51% {
opacity: 0;
}
100% {
-moz-transform: translateX(-10px);
-ms-transform: translateX(-10px);
-webkit-transform: translateX(-10px);
transform: translateX(-10px);
opacity: 0;
}
}
.researchDoor {
fill: #464949;
-moz-animation: translateDoor 5s linear infinite;
-webkit-animation: translateDoor 5s linear infinite;
animation: translateDoor 5s linear infinite;
}
.research0 {
fill: #FFFFFF;
stroke: #464949;
stroke-width: 2;
stroke-miterlimit: 10;
}
.research1 {
fill: #FCBD38;
overflow: hidden;
}
.research2 {
fill: #464949;
}
.research3 {
fill: none;
stroke: #464949;
stroke-width: 2;
stroke-linecap: square;
stroke-miterlimit: 10;
}
<svg version="1.1" x="0px" y="0px" viewBox="0 0 100 120" style="enable-background:new 0 0 100 120;" xml:space="preserve">
<path id="XMLID_42_" class="research0" d="M57.9,25.5c-3-6.4-8.3-11.6-8.3-11.6c-5.1,5-8.3,11.5-8.3,11.5v5.8L57.7,32L57.9,25.5z" />
<g id="XMLID_40_">
<rect x="41.4" y="25.9" class="research1" width="16.3" height="11.5" />
<path class="research2" d="M56.7,26.9v9.5H42.4v-9.5H56.7 M58.7,24.9H40.4v13.5h18.3V24.9L58.7,24.9z" />
</g>
<polygon id="XMLID_43_" class="research3" points="33.5,85.2 40.8,37.7 58.8,37.7 66.2,85.2 " />
<!-- door -->
<rect x="41" y="28.9" class="researchDoor" />
<!-- left top wind -->
<rect x="30" class="glare-top" y="28" fill="#464949" width="14" height="2" />
<!-- left bottom wind -->
<rect x="30" class="glare-bottom" y="32" fill="#464949" width="14" height="2" />
<!-- right top wind -->
<rect x="62" y="28" class="glare-top" fill="#464949" width="14" height="2" />
<!-- right bottom wind -->
<rect x="62" y="32" class="glare-bottom" fill="#464949" width="14" height="2" />
<!--
<line id="glareLeftTop" class="research3" x1="36.6" y1="28.7" x2="32.8" y2="28.7"/>
<line id="glareLeftBottom" class="research3" x1="36.6" y1="33.3" x2="23.8" y2="33.3"/>
<line id="glareTopRight" class="research3" x1="62.9" y1="28.7" x2="66.6" y2="28.7"/>
<line id="glareTopBottom" class="research3" x1="62.9" y1="33.3" x2="75.6" y2="33.3"/>
-->
<line id="XMLID_2_" class="research3" x1="76.3" y1="85.3" x2="23.7" y2="85.3" />
<line id="XMLID_64_" class="research3" x1="60.7" y1="37.7" x2="38.8" y2="37.7" />
<line id="XMLID_70_" class="research3" x1="58.7" y1="44.3" x2="40.8" y2="44.3" />
<line id="XMLID_79_" class="research3" x1="60.2" y1="51.7" x2="39.3" y2="51.7" />
<line id="XMLID_80_" class="research3" x1="61.7" y1="61" x2="37.8" y2="61" />
<line id="XMLID_90_" class="research3" x1="63.5" y1="69.3" x2="36.8" y2="69.3" />
<g id="XMLID_49_">
<path class="research2" d="M49.8,76.2c1.5,0,2.8,1.2,2.8,2.8v5.2H47v-5.2C47,77.4,48.2,76.2,49.8,76.2 M49.8,74.2
c-2.6,0-4.8,2.1-4.8,4.8v7.2h9.5v-7.2C54.5,76.3,52.4,74.2,49.8,74.2L49.8,74.2z" />
</g>
</svg>
Consider using lines with a stroke-width equal to the height of the rectangles instead of rectangles in your animation.
The stroke-dasharray lines will be used for animation.
At 0% {stroke-dasharray: 0.10;} for an animated line equal to 10px
the line will be hidden
At 50% {stroke-dasharray: 10,0;} the line will be shown in full
At 100% {stroke-dasharray: 0.10;} the line will be hidden again
.glare-top {
-webkit-animation: glareAnim1 2s linear infinite;
stroke-dasharray:0,10;
animation: glareAnim1 2s linear infinite;
}
#-webkit-keyframes glareAnim1 {
0% {stroke-dasharray:0,10;}
50% {stroke-dasharray:10,10;}
100%{stroke-dasharray:0,10;}
}
.glare-bottom {
-webkit-animation: glareAnim2 2s linear infinite;
stroke-dasharray:0,10;
animation: glareAnim2 2s linear infinite;
}
#-webkit-keyframes glareAnim2 {
0% {stroke-dasharray:10,0;}
50% {stroke-dasharray:0,10;}
100%{stroke-dasharray:10,0;}
}
<svg version="1.1" viewBox="0 0 100 120" >
<!-- left top wind -->
<polyline class="glare-top" points="27,28 37,28" stroke="#464949" stroke-width="2" />
<!-- left bottom wind -->
<polyline class="glare-bottom" points="27,33 37,33" stroke="#464949" stroke-width="2" />
</svg>
I have shortened your code to show the basic animation of the lines and the door.
svg {
display: inline-block;
}
.glare-top {
-webkit-animation: glareAnim1 2s linear infinite;
stroke-dasharray:0,10;
animation: glareAnim1 2s linear infinite;
}
#-webkit-keyframes glareAnim1 {
0% {stroke-dasharray:0,10;}
50% {stroke-dasharray:10,10;}
100%{stroke-dasharray:0,10;}
}
#keyframes glareAnim1 {
0% {stroke-dasharray:0,10;}
50% {stroke-dasharray:10,10;}
100%{stroke-dasharray:0,10;}
}
.glare-bottom {
-moz-animation: glareAnim2 2s linear infinite;
-webkit-animation: glareAnim2 2s linear infinite;
stroke-dasharray:0,10;
animation: glareAnim2 2s linear infinite;
}
#-webkit-keyframes glareAnim2 {
0% {stroke-dasharray:10,0;}
50% {stroke-dasharray:0,10;}
100%{stroke-dasharray:10,0;}
}
#keyframes glareAnim2 {
0% {stroke-dasharray:10,0;}
50% {stroke-dasharray:0,10;}
100%{stroke-dasharray:10,0;}
}
.researchDoor {
fill: #464949;
stroke-dasharray:0,6;
animation: translateDoor 5s linear infinite;
}
#keyframes translateDoor {
0% {
transform: translate(-1px, 0);
opacity: 1;
stroke-dasharray:0,6;
}
15% {
stroke-dasharray:1.4,4.6;
}
50% {
transform: translate(8px, 0);
stroke-dasharray:5,1;
}
70% {
transform: translate(12.8px, 0);
stroke-dasharray:3.5,2.5;
}
100% {
transform: translateX(16px);
stroke-dasharray:0,6;
}
}
.research0 {
fill: #FFFFFF;
stroke: #464949;
stroke-width: 2;
stroke-miterlimit: 10;
}
.research1 {
fill: #FCBD38;
overflow: hidden;
}
.research2 {
fill: #464949;
}
.research3 {
fill: none;
stroke: #464949;
stroke-width: 2;
stroke-linecap: square;
stroke-miterlimit: 10;
}
<svg version="1.1" viewBox="0 0 100 120" >
<path id="XMLID_42_" class="research0" d="M57.9,25.5c-3-6.4-8.3-11.6-8.3-11.6c-5.1,5-8.3,11.5-8.3,11.5v5.8L57.7,32L57.9,25.5z" />
<g id="XMLID_40_">
<rect x="41.4" y="25.9" class="research1" width="16.3" height="11.5" />
<path class="research2" d="M56.7,26.9v9.5H42.4v-9.5H56.7 M58.7,24.9H40.4v13.5h18.3V24.9L58.7,24.9z" />
</g>
<polygon id="XMLID_43_" class="research3" points="33.5,85.2 40.8,37.7 58.8,37.7 66.2,85.2 " />
<!-- door -->
<!-- <rect x="41" y="28.9" class="researchDoor" /> -->
<polyline class="researchDoor" points="41,32 47,32" stroke="#464949" stroke-width="6" />
<!-- left top wind -->
<polyline class="glare-top" points="27,28 37,28" stroke="#464949" stroke-width="2" />
<!-- right top wind -->
<polyline class="glare-top" points=" 62,28 72,28" stroke="#464949" stroke-width="2" />
<!-- left bottom wind -->
<polyline class="glare-bottom" points="27,33 37,33" stroke="#464949" stroke-width="2" />
<!-- right bottom wind -->
<polyline class="glare-bottom" points=" 62,33 72,33" stroke="#464949" stroke-width="2" />
<line id="XMLID_2_" class="research3" x1="76.3" y1="85.3" x2="23.7" y2="85.3" />
<line id="XMLID_64_" class="research3" x1="60.7" y1="37.7" x2="38.8" y2="37.7" />
<line id="XMLID_70_" class="research3" x1="58.7" y1="44.3" x2="40.8" y2="44.3" />
<line id="XMLID_79_" class="research3" x1="60.2" y1="51.7" x2="39.3" y2="51.7" />
<line id="XMLID_80_" class="research3" x1="61.7" y1="61" x2="37.8" y2="61" />
<line id="XMLID_90_" class="research3" x1="63.5" y1="69.3" x2="36.8" y2="69.3" />
<g id="XMLID_49_">
<path class="research2" d="M49.8,76.2c1.5,0,2.8,1.2,2.8,2.8v5.2H47v-5.2C47,77.4,48.2,76.2,49.8,76.2 M49.8,74.2
c-2.6,0-4.8,2.1-4.8,4.8v7.2h9.5v-7.2C54.5,76.3,52.4,74.2,49.8,74.2L49.8,74.2z" />
</g>
</svg>
In SVG 1.1 width is an attribute and cannot be animated with CSS animation.
In the SVG 2 specification width is a CSS property which can therefore be animated with CSS animation.
Chrome has implemented this part of the SVG 2 specification, Firefox had not when this question was first written, but it has now. In fact Firefox has had this functionality for quite a while now.