Blazor, CSS - Keyframes Animation - html

I made an animation in CSS for a check (right or wrong). The animation is actually the same, only the color is different. My problem now is that the name of the "Keyframes Fill" class is the same ("100%"). So both have the same color in the Fill animation. Is it possible to fix this problem somehow ?
Thanks.
/*=========================================
Checkmark Green Animation
=========================================
*/
.checkmark__circle {
stroke-dasharray: 166;
stroke-dashoffset: 166;
stroke-width: 2;
stroke-miterlimit: 10;
stroke: #7ac142;
fill: none;
animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}
.checkmark {
width: 32px;
height: 32px;
border-radius: 50%;
stroke-width: 2;
stroke: #fff;
stroke-miterlimit: 10;
margin: 10% auto;
box-shadow: inset 0px 0px 0px #7ac142;
animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}
.checkmark__check {
transform-origin: 50% 50%;
stroke-dasharray: 48;
stroke-dashoffset: 48;
animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}
#keyframes stroke {
100% {
stroke-dashoffset: 0;
}
}
#keyframes scale {
0%, 100% {
transform: none;
}
50% {
transform: scale3d(1.1, 1.1, 1);
}
}
#keyframes fill {
100% {
box-shadow: inset 0px 0px 0px 30px #7ac142;
}
}
/*=========================================
Checkmark Red Animation
=========================================
*/
.checkmark__circle_red {
stroke-dasharray: 166;
stroke-dashoffset: 166;
stroke-width: 2;
stroke-miterlimit: 10;
stroke: #ff0000;
fill: none;
animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}
.checkmark_red {
width: 32px;
height: 32px;
border-radius: 50%;
stroke-width: 2;
stroke: #fff;
stroke-miterlimit: 10;
margin: 10% auto;
box-shadow: inset 0px 0px 0px #ff0000;
animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}
.checkmark__check_red {
transform-origin: 50% 50%;
stroke-dasharray: 48;
stroke-dashoffset: 48;
animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}
#keyframes stroke{
100% {
stroke-dashoffset: 0;
}
}
#keyframes scale{
0%, 100% {
transform: none;
}
50% {
transform: scale3d(1.1, 1.1, 1);
}
}
#keyframes fill {
100% {
box-shadow: inset 0px 0px 0px 30px #ff0000;
}
}
<!--Here is actually a C# check made (a function is called), depending on whether the entered is correct or incorrect.-->
<svg class="checkmark" viewBox="0 0 52 52">
<circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/>
<path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
</svg>
<svg class="checkmark_red" viewBox="0 0 52 52">
<circle class="checkmark__circle_red" cx="26" cy="26" r="25" fill="none"/>
<path class="checkmark__check_red" fill="none" d="M14.1 14.1l23.8 23.8 m0,-23.8 l-23.8,23.8"/>
</svg>

Is this the result you wanted? If so, do not set the color in the animation, but before. Sadly there is no box-shadow-color property, but you can use color property. see this SO answer
/*=========================================
Checkmark Green Animation
=========================================
*/
.checkmark__circle {
stroke-dasharray: 166;
stroke-dashoffset: 166;
stroke-width: 2;
stroke-miterlimit: 10;
stroke: #7ac142;
fill: none;
animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}
.checkmark {
width: 32px;
height: 32px;
border-radius: 50%;
stroke-width: 2;
stroke: #fff;
stroke-miterlimit: 10;
margin: 10% auto;
color: #7ac142;
animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}
.checkmark__check {
transform-origin: 50% 50%;
stroke-dasharray: 48;
stroke-dashoffset: 48;
animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}
#keyframes stroke {
100% {
stroke-dashoffset: 0;
}
}
#keyframes scale {
0%, 100% {
transform: none;
}
50% {
transform: scale3d(1.1, 1.1, 1);
}
}
#keyframes fill {
100% {
box-shadow: inset 0px 0px 0px 30px #7ac142;
}
}
/*=========================================
Checkmark Red Animation
=========================================
*/
.checkmark__circle_red {
stroke-dasharray: 166;
stroke-dashoffset: 166;
stroke-width: 2;
stroke-miterlimit: 10;
stroke: #ff0000;
fill: none;
animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}
.checkmark_red {
width: 32px;
height: 32px;
border-radius: 50%;
stroke-width: 2;
stroke: #fff;
stroke-miterlimit: 10;
margin: 10% auto;
color: #ff0000;
animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}
.checkmark__check_red {
transform-origin: 50% 50%;
stroke-dasharray: 48;
stroke-dashoffset: 48;
animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}
#keyframes stroke{
100% {
stroke-dashoffset: 0;
}
}
#keyframes scale{
0%, 100% {
transform: none;
}
50% {
transform: scale3d(1.1, 1.1, 1);
}
}
#keyframes fill {
100% {
box-shadow: inset 0px 0px 0px 30px;
}
}
<svg class="checkmark" viewBox="0 0 52 52">
<circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/>
<path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
</svg>
<svg class="checkmark_red" viewBox="0 0 52 52">
<circle class="checkmark__circle_red" cx="26" cy="26" r="25" fill="none"/>
<path class="checkmark__check_red" fill="none" d="M14.1 14.1l23.8 23.8 m0,-23.8 l-23.8,23.8"/>
</svg>

Related

Increase Size of SVG Animation

I'm using this CSS checkmark animation I found for a success page. It works well, but a bit small. I'd like to increase it in size to about 300 pixels.
I tried increasing the viewBox size to 300, but it didn't work:
<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 300">
<circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/>
<path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
</svg>
What is the correct way to increase the size?
.checkmark__circle {
stroke-dasharray: 166;
stroke-dashoffset: 166;
stroke-width: 2;
stroke-miterlimit: 10;
stroke: #7ac142;
fill: none;
animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}
.checkmark {
width: 56px;
height: 56px;
border-radius: 50%;
display: block;
stroke-width: 2;
stroke: #fff;
stroke-miterlimit: 10;
margin: 10% auto;
box-shadow: inset 0px 0px 0px #7ac142;
animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}
.checkmark__check {
transform-origin: 50% 50%;
stroke-dasharray: 48;
stroke-dashoffset: 48;
animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}
#keyframes stroke {
100% {
stroke-dashoffset: 0;
}
}
#keyframes scale {
0%, 100% {
transform: none;
}
50% {
transform: scale3d(1.1, 1.1, 1);
}
}
#keyframes fill {
100% {
box-shadow: inset 0px 0px 0px 30px #7ac142;
}
}
<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
<circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/>
<path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
</svg>
I've left three comments below indicating the sizes you need to increase, all in CSS:
The SVG width
The SVG height
The shadow "fill" in the animation (set to 50% the size of the width/height)
.checkmark__circle {
stroke-dasharray: 166;
stroke-dashoffset: 166;
stroke-width: 2;
stroke-miterlimit: 10;
stroke: #7ac142;
fill: none;
animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}
.checkmark {
width: 200px; /* 1. change the width here */
height: 200px; /* 2. change the height here */
border-radius: 50%;
display: block;
stroke-width: 2;
stroke: #fff;
stroke-miterlimit: 10;
margin: 10% auto;
box-shadow: inset 0px 0px 0px #7ac142;
animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}
.checkmark__check {
transform-origin: 50% 50%;
stroke-dasharray: 48;
stroke-dashoffset: 48;
animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}
#keyframes stroke {
100% {
stroke-dashoffset: 0;
}
}
#keyframes scale {
0%,
100% {
transform: none;
}
50% {
transform: scale3d(1.1, 1.1, 1);
}
}
#keyframes fill {
100% {
/* 3. change the shadow spread-radius here to 50% the width/height */
box-shadow: inset 0px 0px 0px 100px #7ac142;
}
}
<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52">
<circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/>
<path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/>
</svg>

Need cross instead tick in SVG

I need to convert the tick mark to a cross mark, I have no knowledge of SVG, so anyone can convert the following tick animation to a cross animation?
body {
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.checkmark {
width: 56px;
height: 56px;
border-radius: 50%;
display: block;
stroke-width: 2;
stroke: #fff;
stroke-miterlimit: 10;
box-shadow: inset 0px 0px 0px #7ac142;
animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}
.checkmark__circle {
stroke-dasharray: 166;
stroke-dashoffset: 166;
stroke-width: 2;
stroke-miterlimit: 10;
stroke: #7ac142;
fill: none;
animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}
.checkmark__check {
transform-origin: 50% 50%;
stroke-dasharray: 48;
stroke-dashoffset: 48;
animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}
#keyframes stroke {
100% {
stroke-dashoffset: 0;
}
}
#keyframes scale {
0%, 100% {
transform: none;
}
50% {
transform: scale3d(1.1, 1.1, 1);
}
}
#keyframes fill {
100% {
box-shadow: inset 0px 0px 0px 30px #7ac142;
}
}
<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52"><circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/><path class="checkmark__check" fill="none" d="M14.1 27.2l7.1 7.2 16.7-16.8"/></svg>
I have tried my best but the tick join point doesn't splits, tick tail and head attached, any help will be appreciated.
My thought process:
Not really a StackOverflow-worthy question...
But I am a sucker for SVG
I'm gonna do it anyway.
So here you go! I've just changed the <path /> for you.
d="M14.1 14.1l23.8 23.8 m0,-23.8 l-23.8,23.8"
Start in the top-left (at 14.1,14.1), go diagonally down-right for 23.8 units, then "pick up the pen" and move 23.8 units up before going down-left for 23.8 units.
Looks good to me!
body {
width: 100vw;
height: 100vh;
display: flex;
align-items: center;
justify-content: center;
}
.checkmark {
width: 56px;
height: 56px;
border-radius: 50%;
display: block;
stroke-width: 2;
stroke: #fff;
stroke-miterlimit: 10;
box-shadow: inset 0px 0px 0px #7ac142;
animation: fill .4s ease-in-out .4s forwards, scale .3s ease-in-out .9s both;
}
.checkmark__circle {
stroke-dasharray: 166;
stroke-dashoffset: 166;
stroke-width: 2;
stroke-miterlimit: 10;
stroke: #7ac142;
fill: none;
animation: stroke 0.6s cubic-bezier(0.65, 0, 0.45, 1) forwards;
}
.checkmark__check {
transform-origin: 50% 50%;
stroke-dasharray: 48;
stroke-dashoffset: 48;
animation: stroke 0.3s cubic-bezier(0.65, 0, 0.45, 1) 0.8s forwards;
}
#keyframes stroke {
100% {
stroke-dashoffset: 0;
}
}
#keyframes scale {
0%, 100% {
transform: none;
}
50% {
transform: scale3d(1.1, 1.1, 1);
}
}
#keyframes fill {
100% {
box-shadow: inset 0px 0px 0px 30px #7ac142;
}
}
<svg class="checkmark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 52 52"><circle class="checkmark__circle" cx="26" cy="26" r="25" fill="none"/><path class="checkmark__check" fill="none" d="M14.1 14.1l23.8 23.8 m0,-23.8 l-23.8,23.8"/></svg>

CSS3 : appear check mark and text on the same time

I have a button with check mark and text.I want check mark and text to be appeared on the same time. in my code I get text to be appeared early than check mark.
.sending_btn {
outline: none;
width: 128px;
height: 30px;
border-radius: 2px;
border: thin #3a3f51 solid;
transform-origin: center center;
}
.sending_btn span {
color: #3a3f51;
}
.sending_btn:focus, .sending_btn:active {
padding: 0;
}
svg{
vertical-align:middle;
}
.svg-success {
stroke-width: 2px;
stroke: #3a3f51;
fill: none;
}
.svg-success path {
stroke-dasharray: 17px, 17px;
stroke-dashoffset: 0px;
-webkit-animation: checkmark 0.25s ease-in-out 0.2s backwards;
animation: checkmark 0.25s ease-in-out 0.2s backwards;
}
.svg-success circle {
stroke-dasharray: 76px, 76px;
stroke-dashoffset: 0px;
transform: rotate(-90deg);
transform-origin: 50% 50%;
-webkit-animation: checkmark-circle 0.6s ease-in-out forwards;
animation: checkmark-circle 0.6s ease-in-out forwards;
}
#keyframes checkmark {
0% {
stroke-dashoffset: 17px;
}
100% {
stroke-dashoffset: 0;
}
}
#keyframes checkmark-circle {
0% {
stroke-dashoffset: 76px;
}
100% {
stroke-dashoffset: 0px;
}
}
<button type="button" name="button" class="sending_btn bg-white-only m-t-25px" *ngIf="show_btn == true">
<svg class="v-middle" width="26" height="26" viewBox="-263.5 236.5 26 26">
<g class="svg-success">
<circle cx="-250.5" cy="249.5" r="12"/>
<path d="M-256.46 249.65l3.9 3.74 8.02-7.8"/>
</g>
</svg>
<span class=""> Saved</span></button>
check mark and text should be appeared on the same time and completed on the same time as well.
Any help would be great.
Thank You.
you need to set-up some animation also for the span tag
.sending_btn {
outline: none;
width: 128px;
height: 30px;
border-radius: 2px;
border: thin #3a3f51 solid;
transform-origin: center center;
}
.sending_btn span {
color: #3a3f51;
animation: 1.2s fadeIn;
animation-fill-mode: forwards;
opacity: 0;
}
.sending_btn:focus, .sending_btn:active {
padding: 0;
}
svg{
vertical-align:middle;
}
.svg-success {
stroke-width: 2px;
stroke: #3a3f51;
fill: none;
}
.svg-success path {
stroke-dasharray: 17px, 17px;
stroke-dashoffset: 0px;
-webkit-animation: checkmark 0.25s ease-in-out 0.2s backwards;
animation: checkmark 0.25s ease-in-out 0.2s backwards;
}
.svg-success circle {
stroke-dasharray: 76px, 76px;
stroke-dashoffset: 0px;
transform: rotate(-90deg);
transform-origin: 50% 50%;
-webkit-animation: checkmark-circle 0.6s ease-in-out forwards;
animation: checkmark-circle 0.6s ease-in-out forwards;
}
#keyframes checkmark {
0% {
stroke-dashoffset: 17px;
}
100% {
stroke-dashoffset: 0;
}
}
#keyframes checkmark-circle {
0% {
stroke-dashoffset: 76px;
}
100% {
stroke-dashoffset: 0px;
}
}
#keyframes fadeIn {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
<button type="button" name="button" class="sending_btn bg-white-only m-t-25px" *ngIf="show_btn == true">
<svg class="v-middle" width="26" height="26" viewBox="-263.5 236.5 26 26">
<g class="svg-success">
<circle cx="-250.5" cy="249.5" r="12"/>
<path d="M-256.46 249.65l3.9 3.74 8.02-7.8"/>
</g>
</svg>
<span class=""> Saved</span></button>

Start css3 animation when the content is visible

I've made an animation using svg and now I wonder how to activate it when it shows on the screen. Tried with Scroll Reveal but it doesn't work.
Here is the animation: http://jsfiddle.net/z86026mv/148/light/
HTML
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" x="0px" y="0px" width="136.5px" height="100.15px" viewBox="0 0 136.5 100.15" enable-background="new 0 0 136.5 100.15" xml:space="preserve">
<rect class="key" x="111.284" y="80.95" fill="none" stroke="#000000" stroke-width="6" stroke-miterlimit="10" width="1.02" height="1.02"/>
<path class="phone" fill="none" stroke="#000000" stroke-width="6" stroke-miterlimit="10" d="M102.85 31.275L90.902 43.222v51.003h29.837l11.947-11.946V31.275H102.85z"/>
<polyline class="bottom_line" fill="none" stroke="#000000" stroke-width="6" stroke-miterlimit="10" points="52.476 94.225 65.188 94.225 78.059 94.225 "/>
<line class="vert_line" fill="none" stroke="#000000" stroke-width="6" stroke-miterlimit="10" x1="65.188" y1="94.225" x2="65.188" y2="81.969"/>
<polyline class="screen" fill="none" stroke="#000000" stroke-width="6" stroke-miterlimit="10" points="120.74 22.27 120.74 5.924 3.813 5.924 3.813 81.969 82.262 81.969 "/>
CSS
/*Animacje*/
svg * {
fill: none;
stroke: currentColor;
stroke-linecap: square;
stroke-linejoin: miter;
color: #100F0D;
stroke-width: 6;
stroke-miterlimit: 10;
}
.phone {
animation: draw 1.5s cubic-bezier(1, 0.1, 0, 0.87) alternate;
-webkit-animation: draw 1.5s cubic-bezier(1, 0.1, 0, 0.87) alternate;
}
#keyframes draw {
0% {
stroke-dashoffset: 192;
stroke-dasharray: 192;
}
100% {
stroke-dashoffset: 0;
stroke-dasharray: 192;
}
}
.screen {
animation: screen 1.5s cubic-bezier(1, 0.1, 0, 0.87) alternate;
-webkit-animation: screen 1.5s cubic-bezier(1, 0.1, 0, 0.87) alternate;
fill-opacity: 0;
stroke: #000;
stroke-width: 6;
}
#keyframes screen {
0% {
stroke-dashoffset: 290;
stroke-dasharray: 290;
}
100% {
stroke-dashoffset: 0;
stroke-dasharray: 290;
}
}
.bottom_line {
position: absolute;
opacity: 0;
-webkit-animation: bottom_line 1s cubic-bezier(1, 0.1, 0, 0.87) 1s forwards;
-moz-animation: bottom_line 1s cubic-bezier(1, 0.1, 0, 0.87) 1s forwards;
-o-animation: bottom_line 1s cubic-bezier(1, 0.1, 0, 0.87) 1s forwards;
animation: bottom_line 1s cubic-bezier(1, 0.1, 0, 0.87) 1s forwards;
}
#keyframes bottom_line {
0% {
opacity: 1;
stroke-dashoffset: 290;
stroke-dasharray: 290;
}
100% {
opacity: 1;
stroke-dashoffset: 0;
stroke-dasharray: 290;
}
}
.vert_line{
position: absolute;
opacity: 0;
-webkit-animation: vert_line 1s cubic-bezier(1, 0.1, 0, 0.87) 1s forwards;
-moz-animation: vert_line 1s cubic-bezier(1, 0.1, 0, 0.87) 1s forwards;
-o-animation: vert_line 1s cubic-bezier(1, 0.1, 0, 0.87) 1s forwards;
animation: vert_line 1s cubic-bezier(1, 0.1, 0, 0.87) 1s forwards;
}
#keyframes vert_line {
0% {
opacity: 1;
stroke-dashoffset: 290;
stroke-dasharray: 290;
}
100% {
opacity: 1;
stroke-dashoffset: 0;
stroke-dasharray: 290;
}
}
.key {
position: absolute;
opacity: 0;
-webkit-animation: key 1s ease 1s forwards;
-moz-animation: key 1s ease 1s forwards;
-o-animation: key 1s ease 1s forwards;
animation: key 1s ease 1s forwards;
}
#keyframes key {
0% {
opacity: 0;
transform: translate(-35px,0px);
-ms-transform: translate(-35px,0px); /* IE 9 */
-webkit-transform: translate(-35px,0px); /* Safari and Chrome */
-o-transform: translate(-35px,0px); /* Opera */
-moz-transform: translate(-35px,0px); /* Firefox */
}
100% {
opacity: 1;
transform: translate(0,0px);
-ms-transform: translate(0,0px); /* IE 9 */
-webkit-transform: translate(0,0px); /* Safari and Chrome */
-o-transform: translate(0,0px); /* Opera */
-moz-transform: translate(0,0px); /* Firefox */
}
}
#-webkit-keyframes key {
0% {
opacity: 0;
}
100% {
opacity: 1;
}
}
And here, in the "Service" section I have placed it. http://flowagency.nu/index_ico.php
Do you have any ideas?
Thx in advance.
you can set the display of the svg to none var svg = document.getElementsByTagName("svg")[0];
svg.style.display='none'; then when you click on the service tab you can set the display to block svg.style.display='block'; watch out the example below i did the second step using setTimeout you can do it with click or whatever you like
http://jsfiddle.net/z86026mv/149/

How to change size of SVG circle

I want to resize my first SVG circle from here, so I made the second, but there is a problem in the animation, the animation is not the same.
HTML:
<div class="loader">
<svg class="circular">
<circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="8" stroke-miterlimit="10" />
</svg>
</div>
<div style="margin-top: 50px;" class="loader">
<svg class="circular">
<circle class="path" cx="50" cy="50" r="44" fill="none" stroke-width="8" stroke-miterlimit="10" />
</svg>
</div>
CSS:
body, svg, circle {
margin: 0px !important;
padding: 0px !important;
}
.loader {
position: relative;
margin: 0px auto;
padding: 0px;
width: 100px;
height: 100px;
zoom: 1;
background-color: grey;
}
.circular {
-webkit-animation: rotate 3s linear infinite;
animation: rotate 3s linear infinite;
height: 100px;
position: relative;
width: 100px;
}
.path {
stroke-dasharray: 1, 200;
stroke-dashoffset: 0;
-webkit-animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
stroke-linecap: round;
}
#-webkit-keyframes rotate {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes rotate {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-webkit-keyframes dash {
0% {
stroke-dasharray: 1, 200;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 89, 200;
stroke-dashoffset: -35;
}
100% {
stroke-dasharray: 89, 200;
stroke-dashoffset: -124;
}
}
#keyframes dash {
0% {
stroke-dasharray: 1, 200;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 89, 200;
stroke-dashoffset: -35;
}
100% {
stroke-dasharray: 89, 200;
stroke-dashoffset: -124;
}
}
#-webkit-keyframes color {
100%, 0% {
stroke: #d62d20;
}
40% {
stroke: #0057e7;
}
66% {
stroke: #008744;
}
80%, 90% {
stroke: #ffa700;
}
}
#keyframes color {
100%, 0% {
stroke: #d62d20;
}
40% {
stroke: #0057e7;
}
66% {
stroke: #008744;
}
80%, 90% {
stroke: #ffa700;
}
}
How to properly resize it?
The stroke-dasharray property of the circle element determine the length of the stroke's dash and the space between two dashes whereas the stroke-dashoffset determines the offset at which the stroke's dash starts. Within the #keyframes rules these properties are getting modified and thus ends up producing the animation effect. When the circle's radius (and thus the circumference) is changed, these properties (set within the keyframes) also have to modified in proportion to the radius.
Since the settings depend on the radius of the circle, I don't think you can keep the same animation (#keyframe) settings for both circles. At any time only one of them can work properly.
In the below snippet I have done the changes that are required to make the bigger circle work.
body,
svg,
circle {
margin: 0px !important;
padding: 0px !important;
}
.loader {
position: relative;
margin: 0px auto;
padding: 0px;
width: 100px;
height: 100px;
zoom: 1;
background-color: grey;
}
.circular {
-webkit-animation: rotate 3s linear infinite;
animation: rotate 3s linear infinite;
height: 100px;
position: relative;
width: 100px;
}
.path {
stroke-dasharray: 1, 440;
stroke-dashoffset: 0;
-webkit-animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
stroke-linecap: round;
}
#-webkit-keyframes rotate {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes rotate {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-webkit-keyframes dash {
0% {
stroke-dasharray: 1, 440;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 89, 440;
stroke-dashoffset: -77;
}
100% {
stroke-dasharray: 89, 440;
stroke-dashoffset: -272;
}
}
#keyframes dash {
0% {
stroke-dasharray: 1, 440;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 89, 440;
stroke-dashoffset: -77;
}
100% {
stroke-dasharray: 89, 440;
stroke-dashoffset: -272;
}
}
#-webkit-keyframes color {
100%, 0% {
stroke: #d62d20;
}
40% {
stroke: #0057e7;
}
66% {
stroke: #008744;
}
80%,
90% {
stroke: #ffa700;
}
}
#keyframes color {
100%, 0% {
stroke: #d62d20;
}
40% {
stroke: #0057e7;
}
66% {
stroke: #008744;
}
80%,
90% {
stroke: #ffa700;
}
}
<div style="margin-top: 50px;" class="loader">
<svg class="circular">
<circle class="path" cx="50" cy="50" r="44" fill="none" stroke-width="8" stroke-miterlimit="10" />
</svg>
</div>
Alternately, if you wish to make the same animation (#keyframe) settings work for both the circles at the same time, then you could consider using a transform: scale to create the bigger circle instead of manually modifying the radius of the circle. (But as you can see, the output is not exactly same as modifying the radius and hence I wouldn't really recommend this).
body,
svg,
circle {
margin: 0px !important;
padding: 0px !important;
}
.loader {
position: relative;
margin: 0px auto;
padding: 0px;
width: 100px;
height: 100px;
zoom: 1;
background-color: grey;
}
.circular {
-webkit-animation: rotate 3s linear infinite;
animation: rotate 3s linear infinite;
height: 100px;
position: relative;
width: 100px;
}
.path {
stroke-dasharray: 1, 200;
stroke-dashoffset: 0;
-webkit-animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
animation: dash 1.5s ease-in-out infinite, color 6s ease-in-out infinite;
stroke-linecap: round;
}
#-webkit-keyframes rotate {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#keyframes rotate {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#-webkit-keyframes dash {
0% {
stroke-dasharray: 1, 200;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 89, 200;
stroke-dashoffset: -35;
}
100% {
stroke-dasharray: 89, 200;
stroke-dashoffset: -124;
}
}
#keyframes dash {
0% {
stroke-dasharray: 1, 200;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 89, 200;
stroke-dashoffset: -35;
}
100% {
stroke-dasharray: 89, 200;
stroke-dashoffset: -124;
}
}
#-webkit-keyframes color {
100%, 0% {
stroke: #d62d20;
}
40% {
stroke: #0057e7;
}
66% {
stroke: #008744;
}
80%,
90% {
stroke: #ffa700;
}
}
#keyframes color {
100%, 0% {
stroke: #d62d20;
}
40% {
stroke: #0057e7;
}
66% {
stroke: #008744;
}
80%,
90% {
stroke: #ffa700;
}
}
.loader2 {
transform: scale(2.2);
}
<div class="loader">
<svg class="circular">
<circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="8" stroke-miterlimit="10" />
</svg>
</div>
<div style="margin-top: 100px;" class="loader loader2">
<svg class="circular">
<circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="8" stroke-miterlimit="10" />
</svg>
</div>