CSS Progress circle, change percentage - html

I have found the following code, Link, it works perfectly but the problem is that I can only make the percentage 25, 50 or 75. If I want to make it 85% the circle fills up fully. Anyone any idea what I have to do? Maybe some JavaScript or JQuery that I have to add? Thanks!
Here is the HTML:
/* Import the Google Font 'Lato' */
#import url(http://fonts.googleapis.com/css?family=Lato:300,400,700);
/* Container styles */
body {
background-color: #fff;
color: #333;
font-family: 'Lato';
}
.container {
padding: 50px 0;
text-align: center;
}
.chart {
position: relative;
display: inline-block;
color: #999;
font-size: 20px;
text-align: center;
}
.chart figcaption {
padding: 50px 25px;
width: 100px;
height: 50px;
border: 20px solid #f0f0f0;
border-radius: 100px;
line-height: 50px;
}
.chart img {
position: absolute;
max-width: 100px;
max-height: 100px;
background: white;
}
/* END Container styles */
/* Colors for the circles and positions for the graphics */
.html {
top: 50px;
left: 45px;
}
.html + svg .outer {
stroke: #e34f26;
}
.css {
top: 55px;
left: 48px;
}
.css + svg .outer {
stroke: #0d84ce;
}
.javascript {
max-width: 90px;
max-height: 90px;
top: 45px;
left: 45px;
}
.javascript + svg .outer {
stroke: #f0e040;
}
.node {
width: 200px;
height: 200px;
top: 45px;
left: 45px;
}
.node + svg .outer {
stroke: #83cd29;
}
.chart svg {
position: absolute;
top: 0;
left: 0;
}
.outer {
fill: transparent;
stroke: #333;
stroke-width: 20;
stroke-dasharray: 534;
transition: stroke-dashoffset 1s;
-webkit-animation-play-state: running;
/* firefox bug fix - won't rotate at 90deg angles */
-moz-transform: rotate(-89deg) translateX(-190px);
}
.chart:hover .outer {
stroke-dashoffset: 534 !important;
-webkit-animation-play-state: paused;
}
/* END Circle colors and graphic positions */
/* Set the initial values for the animation */
.chart[data-percent='100'] .outer {
stroke-dashoffset: 0;
-webkit-animation: show100 2s;
animation: show100 2s;
}
.chart[data-percent='75'] .outer {
stroke-dashoffset: 133;
-webkit-animation: show75 2s;
animation: show75 2s;
}
.chart[data-percent='50'] .outer {
stroke-dashoffset: 267;
-webkit-animation: show50 2s;
animation: show50 2s;
}
.chart[data-percent='25'] .outer {
stroke-dashoffset: 401;
-webkit-animation: show25 2s;
animation: show25 2s;
}
/* END set initial animation values */
/* Keyframes for the initial animation */
#-webkit-keyframes show100 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 0;
}
}
#keyframes show100 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 0;
}
}
#-webkit-keyframes show75 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 134;
}
}
#keyframes show75 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 124;
}
}
#-webkit-keyframes show50 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 267;
}
}
#keyframes show50 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 267;
}
}
#-webkit-keyframes show25 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 401;
}
}
#keyframes show25 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 401;
}
}
/* END Keyframes for the initial animation */
<section class="container">
<h3>I'm a web developer and here's what I can do</h3>
<!-- HTML Chart -->
<div class="chart" data-percent="85">
<figcaption>HTML</figcaption>
<img class="html" src="https://dl.dropboxusercontent.com/s/68gv23q4y5qyq52/html5.svg">
<svg width="200" height="200">
<circle class="outer" cx="95" cy="95" r="85" transform="rotate(-90, 95, 95)"/>
</svg>
</div>
<!-- CSS Chart -->
<figure class="chart" data-percent="75">
<figcaption>CSS</figcaption>
<img class="css" src="https://dl.dropboxusercontent.com/s/gftbpqje9h2jvlv/css3.svg">
<svg width="200" height="200">
<circle class="outer" cx="95" cy="95" r="85" transform="rotate(-90, 95, 95)"/>
</svg>
</figure>
<!-- Javascript Chart -->
<figure class="chart" data-percent="50">
<figcaption>Javascript</figcaption>
<img class="javascript" src="https://dl.dropboxusercontent.com/s/jsp3rsberc4q650/javascript.svg">
<svg width="200" height="200">
<circle class="outer" cx="95" cy="95" r="85" transform="rotate(-90, 95, 95)"/>
</svg>
</figure>
<!-- Node.js Chart -->
<figure class="chart" data-percent="25">
<figcaption>Node</figcaption>
<img class="node" src="https://dl.dropboxusercontent.com/s/v28zws1p38tjph2/node.png">
<svg width="200" height="200">
<circle class="outer" cx="95" cy="95" r="85" transform="rotate(-90, 95, 95)"/>
</svg>
</figure>
<p>Pure CSS and SVG animation</p>
</section>

Iy's not a script so it's not automatically fit to any percentage. In that pen, the author defined only those 4 percentage. Here I added 85% too. But if you want to do this dynamically, you need to use a script.
Take a look:
/* Import the Google Font 'Lato' */
#import url(http://fonts.googleapis.com/css?family=Lato:300,400,700);
/* Container styles */
body {
background-color: #fff;
color: #333;
font-family: 'Lato';
}
.container {
padding: 50px 0;
text-align: center;
}
.chart {
position: relative;
display: inline-block;
color: #999;
font-size: 20px;
text-align: center;
}
.chart figcaption {
padding: 50px 25px;
width: 100px;
height: 50px;
border: 20px solid #f0f0f0;
border-radius: 100px;
line-height: 50px;
}
.chart img {
position: absolute;
max-width: 100px;
max-height: 100px;
background: white;
}
/* END Container styles */
/* Colors for the circles and positions for the graphics */
.html {
top: 50px;
left: 45px;
}
.html + svg .outer {
stroke: #e34f26;
}
.css {
top: 55px;
left: 48px;
}
.css + svg .outer {
stroke: #0d84ce;
}
.javascript {
max-width: 90px;
max-height: 90px;
top: 45px;
left: 45px;
}
.javascript + svg .outer {
stroke: #f0e040;
}
.node {
width: 200px;
height: 200px;
top: 45px;
left: 45px;
}
.node + svg .outer {
stroke: #83cd29;
}
.chart svg {
position: absolute;
top: 0;
left: 0;
}
.outer {
fill: transparent;
stroke: #333;
stroke-width: 20;
stroke-dasharray: 534;
transition: stroke-dashoffset 1s;
-webkit-animation-play-state: running;
/* firefox bug fix - won't rotate at 90deg angles */
-moz-transform: rotate(-89deg) translateX(-190px);
}
.chart:hover .outer {
stroke-dashoffset: 534 !important;
-webkit-animation-play-state: paused;
}
/* END Circle colors and graphic positions */
/* Set the initial values for the animation */
.chart[data-percent='100'] .outer {
stroke-dashoffset: 0;
-webkit-animation: show100 2s;
animation: show100 2s;
}
.chart[data-percent='85'] .outer {
stroke-dashoffset: 83;
-webkit-animation: show85 2s;
animation: show85 2s;
}
.chart[data-percent='75'] .outer {
stroke-dashoffset: 133;
-webkit-animation: show75 2s;
animation: show75 2s;
}
.chart[data-percent='50'] .outer {
stroke-dashoffset: 267;
-webkit-animation: show50 2s;
animation: show50 2s;
}
.chart[data-percent='25'] .outer {
stroke-dashoffset: 401;
-webkit-animation: show25 2s;
animation: show25 2s;
}
/* END set initial animation values */
/* Keyframes for the initial animation */
#-webkit-keyframes show100 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 0;
}
}
#keyframes show100 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 0;
}
}
#-webkit-keyframes show85 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 83;
}
}
#keyframes show85 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 83;
}
}
#-webkit-keyframes show75 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 134;
}
}
#keyframes show75 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 124;
}
}
#-webkit-keyframes show50 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 267;
}
}
#keyframes show50 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 267;
}
}
#-webkit-keyframes show25 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 401;
}
}
#keyframes show25 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 401;
}
}
/* END Keyframes for the initial animation */
<section class="container">
<h3>I'm a web developer and here's what I can do</h3>
<!-- HTML Chart -->
<div class="chart" data-percent="85">
<figcaption>HTML</figcaption>
<img class="html" src="https://dl.dropboxusercontent.com/s/68gv23q4y5qyq52/html5.svg">
<svg width="200" height="200">
<circle class="outer" cx="95" cy="95" r="85" transform="rotate(-90, 95, 95)"/>
</svg>
</div>
<!-- CSS Chart -->
<figure class="chart" data-percent="75">
<figcaption>CSS</figcaption>
<img class="css" src="https://dl.dropboxusercontent.com/s/gftbpqje9h2jvlv/css3.svg">
<svg width="200" height="200">
<circle class="outer" cx="95" cy="95" r="85" transform="rotate(-90, 95, 95)"/>
</svg>
</figure>
<!-- Javascript Chart -->
<figure class="chart" data-percent="50">
<figcaption>Javascript</figcaption>
<img class="javascript" src="https://dl.dropboxusercontent.com/s/jsp3rsberc4q650/javascript.svg">
<svg width="200" height="200">
<circle class="outer" cx="95" cy="95" r="85" transform="rotate(-90, 95, 95)"/>
</svg>
</figure>
<!-- Node.js Chart -->
<figure class="chart" data-percent="25">
<figcaption>Node</figcaption>
<img class="node" src="https://dl.dropboxusercontent.com/s/v28zws1p38tjph2/node.png">
<svg width="200" height="200">
<circle class="outer" cx="95" cy="95" r="85" transform="rotate(-90, 95, 95)"/>
</svg>
</figure>
<p>Pure CSS and SVG animation</p>
</section>

Related

CSS animated SVG disappears when container gets too small

I have create a CSS animation. For the most part, it works as expected.
You can find and test it here: (The weird colors are only for testing...)
https://jsfiddle.net/ec3j8k0r/5/
.svgContainer
{
position: relative;
/*display: inline-block;*/
height: 150px;
width: 150px;
background-color: red;
color: white;
}
.svgCircleBig
{
position:absolute;
/*display: inline-block;*/
height: 100%;
width: 100%;
background-color: transparent;
}
.svgCircleMedium
{
/*display: inline-block;*/
position: absolute;
height: 60%;
width: 60%;
top: 20%;
left: 20%;
background-color: forestgreen;
}
.svgCircleSmall
{
/*display: inline-block;*/
position: absolute;
height: 60%;
width: 60%;
top: 20%;
left: 20%;
background-color: blue;
}
.svgColor
{
fill: white;
stroke: white;
stroke-miterlimit: 1;
}
#-webkit-keyframes rotateRightKeyFrames
{
from
{
-webkit-transform: rotate(0deg);
}
to
{
-webkit-transform: rotate(360deg);
}
}
.rotateRight
{
-webkit-animation: rotateRightKeyFrames 3s linear infinite;
}
.rotateRightFast
{
-webkit-animation: rotateRightKeyFrames 4s linear infinite;
}
#-webkit-keyframes rotateLeftKeyFrames
{
from
{
-webkit-transform: rotate(360deg);
}
to
{
-webkit-transform: rotate(0deg);
}
}
.rotateLeft
{
-webkit-animation: rotateLeftKeyFrames 2s linear infinite;
}
<div class="svgContainer">
<div class="svgCircleBig">
<svg class="rotateRight" viewBox="0 0 90 90">
<use xlink:href="#gear" />
</svg>
<div class="svgCircleMedium">
<svg class="rotateLeft" viewBox="0 0 90 90">
<use xlink:href="#gear" />
</svg>
<div class="svgCircleSmall">
<svg class="rotateRightFast" viewBox="0 0 90 90">
<use xlink:href="#gear"/>
</svg>
</div>
</div>
</div>
</div>
<div style="visibility:collapse; display:none;">
<svg viewBox="0 0 90 90">
<g id="gear"><path class="svgColor" d="M90,46.6v-4l-6.2-2.4c-.2-1.6-.5-3.2-.8-4.7l5-4.4a23.49,23.49,0,0,0-1.4-3.7l-6.7-.2a33.76,33.76,0,0,0-2.4-4.1l3.2-5.8a36.12,36.12,0,0,0-2.5-3l-6.3,2.1c-1.2-1.1-2.4-2.1-3.7-3.1l1-6.6a37.91,37.91,0,0,0-3.4-2L60.6,8.9a40.38,40.38,0,0,0-4.5-1.6L54.8.8C53.5.5,52.2.3,50.9.1L47.4,5.8A9.74,9.74,0,0,0,45,5.6a19.27,19.27,0,0,0-2.4.1L39.1,0c-1.3.2-2.6.4-3.9.7L33.9,7.2c-1.5.5-3,1-4.5,1.6L24.2,4.6a37.91,37.91,0,0,0-3.4,2l1,6.6c-1.3,1-2.5,2-3.7,3.1l-6.3-2.1c-.9,1-1.7,2-2.5,3L12.5,23a33.76,33.76,0,0,0-2.4,4.1l-6.7.2c-.5,1.2-1,2.4-1.4,3.7l5,4.4a35.45,35.45,0,0,0-.8,4.7L0,42.6v4L6.2,49c.2,1.6.5,3.2.8,4.7L2,58.1a23.49,23.49,0,0,0,1.4,3.7l6.7.2a33.76,33.76,0,0,0,2.4,4.1L9.3,71.9a36.12,36.12,0,0,0,2.5,3l6.3-2.1c1.2,1.1,2.4,2.1,3.7,3.1l-1,6.6a37.91,37.91,0,0,0,3.4,2l5.2-4.2a40.38,40.38,0,0,0,4.5,1.6l1.3,6.5c1.3.3,2.6.5,3.9.7l3.5-5.7c.8,0,1.6.1,2.4.1a19.27,19.27,0,0,0,2.4-.1l3.5,5.7c1.3-.2,2.6-.4,3.9-.7l1.3-6.5c1.5-.5,3-1,4.5-1.6l5.2,4.2a37.91,37.91,0,0,0,3.4-2l-1-6.6c1.3-1,2.5-2,3.7-3.1l6.3,2.1c.9-1,1.7-2,2.5-3l-3.2-5.8A33.76,33.76,0,0,0,79.9,62l6.7-.2c.5-1.2,1-2.4,1.4-3.7l-5-4.4a35.45,35.45,0,0,0,.8-4.7ZM45,78.7A34.1,34.1,0,1,1,79.1,44.6,34.14,34.14,0,0,1,45,78.7Z" /></g>
</svg>
</div>
My problem: If the svgContainer class gets too small, let's say only 30px, the most inner animation, with the blue background, disappears to the bottom.
.svgContainer
{
position: relative;
/*display: inline-block;*/
height: 30px;
width: 30px;
background-color: red;
color: white;
}
You can see it live, when changing the CSS code in the fiddle.
My question: Can somebody see what the problem is?
Add display:block to all your SVG elements:
svg {
display:block;
}
.svgContainer {
position: relative;
height: 30px;
width: 30px;
background-color: red;
color: white;
}
.svgCircleBig {
position: absolute;
height: 100%;
width: 100%;
background-color: transparent;
}
.svgCircleMedium {
position: absolute;
height: 60%;
width: 60%;
top: 20%;
left: 20%;
background-color: forestgreen;
}
.svgCircleSmall {
position: absolute;
height: 60%;
width: 60%;
top: 20%;
left: 20%;
background-color: blue;
}
.svgColor {
fill: white;
stroke: white;
stroke-miterlimit: 1;
}
#-webkit-keyframes rotateRightKeyFrames {
from {
-webkit-transform: rotate(0deg);
}
to {
-webkit-transform: rotate(360deg);
}
}
.rotateRight {
-webkit-animation: rotateRightKeyFrames 3s linear infinite;
}
.rotateRightFast {
-webkit-animation: rotateRightKeyFrames 4s linear infinite;
}
#-webkit-keyframes rotateLeftKeyFrames {
from {
-webkit-transform: rotate(360deg);
}
to {
-webkit-transform: rotate(0deg);
}
}
.rotateLeft {
-webkit-animation: rotateLeftKeyFrames 2s linear infinite;
}
<div class="svgContainer">
<div class="svgCircleBig">
<svg class="rotateRight" viewBox="0 0 90 90">
<use xlink:href="#gear" />
</svg>
<div class="svgCircleMedium">
<svg class="rotateLeft" viewBox="0 0 90 90">
<use xlink:href="#gear" />
</svg>
<div class="svgCircleSmall">
<svg class="rotateRightFast" viewBox="0 0 90 90">
<use xlink:href="#gear"/>
</svg>
</div>
</div>
</div>
</div>
<div style="visibility:collapse; display:none;">
<svg viewBox="0 0 90 90">
<g id="gear"><path class="svgColor" d="M90,46.6v-4l-6.2-2.4c-.2-1.6-.5-3.2-.8-4.7l5-4.4a23.49,23.49,0,0,0-1.4-3.7l-6.7-.2a33.76,33.76,0,0,0-2.4-4.1l3.2-5.8a36.12,36.12,0,0,0-2.5-3l-6.3,2.1c-1.2-1.1-2.4-2.1-3.7-3.1l1-6.6a37.91,37.91,0,0,0-3.4-2L60.6,8.9a40.38,40.38,0,0,0-4.5-1.6L54.8.8C53.5.5,52.2.3,50.9.1L47.4,5.8A9.74,9.74,0,0,0,45,5.6a19.27,19.27,0,0,0-2.4.1L39.1,0c-1.3.2-2.6.4-3.9.7L33.9,7.2c-1.5.5-3,1-4.5,1.6L24.2,4.6a37.91,37.91,0,0,0-3.4,2l1,6.6c-1.3,1-2.5,2-3.7,3.1l-6.3-2.1c-.9,1-1.7,2-2.5,3L12.5,23a33.76,33.76,0,0,0-2.4,4.1l-6.7.2c-.5,1.2-1,2.4-1.4,3.7l5,4.4a35.45,35.45,0,0,0-.8,4.7L0,42.6v4L6.2,49c.2,1.6.5,3.2.8,4.7L2,58.1a23.49,23.49,0,0,0,1.4,3.7l6.7.2a33.76,33.76,0,0,0,2.4,4.1L9.3,71.9a36.12,36.12,0,0,0,2.5,3l6.3-2.1c1.2,1.1,2.4,2.1,3.7,3.1l-1,6.6a37.91,37.91,0,0,0,3.4,2l5.2-4.2a40.38,40.38,0,0,0,4.5,1.6l1.3,6.5c1.3.3,2.6.5,3.9.7l3.5-5.7c.8,0,1.6.1,2.4.1a19.27,19.27,0,0,0,2.4-.1l3.5,5.7c1.3-.2,2.6-.4,3.9-.7l1.3-6.5c1.5-.5,3-1,4.5-1.6l5.2,4.2a37.91,37.91,0,0,0,3.4-2l-1-6.6c1.3-1,2.5-2,3.7-3.1l6.3,2.1c.9-1,1.7-2,2.5-3l-3.2-5.8A33.76,33.76,0,0,0,79.9,62l6.7-.2c.5-1.2,1-2.4,1.4-3.7l-5-4.4a35.45,35.45,0,0,0,.8-4.7ZM45,78.7A34.1,34.1,0,1,1,79.1,44.6,34.14,34.14,0,0,1,45,78.7Z" /></g>
</svg>
</div>

Resizing svg element

I need a flexible svg element, but this is the first time using it.
I tried to change the width, heigh & even set positioning property for the circle but none of them work. How to resize this circle?
Thanks in advance
.chart {
position: relative;
display: inline-block;
color: #999;
font-size: 20px;
text-align: center;
}
.chart figcaption {
position: absolute;
top: 38%;
left: 39%;
}
.outer {
fill: transparent;
stroke: #333;
stroke-width: 20;
stroke-dasharray: 534;
transition: stroke-dashoffset 1s;
-webkit-animation-play-state: running;
/* firefox bug fix - won't rotate at 90deg angles */
-moz-transform: rotate(-89deg) translateX(-190px);
}
.chart[data-percent="75"] .outer {
stroke-dashoffset: 133;
//stroke-dashoffset: 50;
-webkit-animation: show75 2s;
animation: show75 2s;
}
#keyframes show75 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 124;
}
}
<div class="container text-center">
<figure class="chart" data-percent="75">
<figcaption>45%</figcaption>
<svg width="200" height="200">
<circle class="outer mr-auto ml-auto" cx="95" cy="95" r="85" transform="rotate(-90, 95, 95)"></circle>
</svg>
</figure>
</div>
When i resize the circle i got something like this:Resized circle
Don't use a set height or width on the SVG, use the viewbox attribute instead
<svg viewbox="0 0 200 200">
Then the SVG will scale to any size you want just by using a width on the parent container.
The viewBox attribute defines the position and dimension, in user space, of an SVG viewport.
Viewbox # MDN
.container.text-center {
/* for demo */
display: inline-block;
text-align: center;
}
.chart {
position: relative;
display: inline-block;
color: #999;
font-size: 20px;
width: 100px;
/* size here */
}
.chart figcaption {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
.outer {
fill: transparent;
stroke: #333;
stroke-width: 20;
stroke-dasharray: 534;
transition: stroke-dashoffset 1s;
-webkit-animation-play-state: running;
/* firefox bug fix - won't rotate at 90deg angles */
-moz-transform: rotate(-89deg) translateX(-190px);
}
.chart[data-percent="75"] .outer {
stroke-dashoffset: 133;
//stroke-dashoffset: 50;
-webkit-animation: show75 2s;
animation: show75 2s;
}
#keyframes show75 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 124;
}
}
.chart.wide {
width: 150px;
}
<div class="container text-center">
<figure class="chart" data-percent="75">
<figcaption>45%</figcaption>
<svg viewbox="0 0 200 200">
<circle class="outer mr-auto ml-auto" cx="95" cy="95" r="85" transform="rotate(-90, 95, 95)"></circle>
</svg>
</figure>
</div>
<div class="container text-center">
<figure class="chart wide" data-percent="75">
<figcaption>45%</figcaption>
<svg viewbox="0 0 200 200">
<circle class="outer mr-auto ml-auto" cx="95" cy="95" r="85" transform="rotate(-90, 95, 95)"></circle>
</svg>
</figure>
</div>
Using the transform property you can scale the circle however you want. For example: using transform: scale(0.5,0.5); will scale the circle to half width and height. W3 Schools shows how this works nicely.
However, you can't transform text, so you will have to move it manually.
.chart {
position: relative;
display: inline-block;
color: #999;
font-size: 20px;
text-align: center;
}
.chart figcaption {
position: absolute;
top: 18%;
left: 15%;
}
.outer {
fill: transparent;
stroke: #333;
stroke-width: 20;
stroke-dasharray: 534;
transition: stroke-dashoffset 1s;
-webkit-animation-play-state: running;
/* firefox bug fix - won't rotate at 90deg angles */
-moz-transform: rotate(-89deg) translateX(-190px);
}
.chart[data-percent="75"] .outer {
stroke-dashoffset: 133;
//stroke-dashoffset: 50;
-webkit-animation: show75 2s;
animation: show75 2s;
transform: scale(0.5, 0.5);
}
#keyframes show75 {
from {
stroke-dashoffset: 537;
}
to {
stroke-dashoffset: 124;
}
}
<div class="container text-center">
<figure class="chart" data-percent="75" transform="">
<figcaption>45%</figcaption>
<svg width="200" height="200">
<circle class="outer mr-auto ml-auto" cx="95" cy="95" r="85" transform="rotate(-90, 95, 95)"></circle>
</svg>
</figure>
</div>

CSS animation on mac vs windows

I'm trying to create a spinner animation but i've encountered some issues with the difference between windows and mac displays.
The animation is a pretty basic circular spinner created with html and css
<div class="cow-spinner">
<span></span>
<span></span>
<span></span>
<span></span>
</div>
and some basic css:
.cow-spinner {
display: inline-block;
position: relative;
width: 64px;
height: 64px;
}
.cow-spinner span {
box-sizing: border-box;
display: block;
position: absolute;
width: 51px;
height: 51px;
margin: 6px;
border: 3px solid black;
border-radius: 50%;
animation: cow-spin 1.2s ease-in-out infinite;
border-color: black transparent transparent transparent;
}
.cow-spinner span:nth-child(1) {
animation-delay: -0.45s;
}
.cow-spinner span:nth-child(2) {
animation-delay: -0.3s;
}
.cow-spinner span:nth-child(3) {
animation-delay: -0.15s;
}
#keyframes cow-spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
The animation itself works perfectly, with a working example here: https://codepen.io/fatoilyguy/pen/oaZMMp
My issue is that on mac the circle itself has smooth edges with consistent width like so:
but on windows, the circle is pixelated and has weird width variations:
From what I can see, there is no difference between browsers on either platform. Is there any way i could prevent this difference from happening between platforms?
You could try a SVG approach and check if the rendering it's good everywhere
.loader {
display: inline-block;
height: 100px;
width: 100px;
transform: rotateZ(0deg);
animation: rotate 1.5s linear infinite;
}
svg {
max-width: 140px;
max-height: 140px;
fill: none;
stroke: #9bc;
stroke-width: 5px;
stroke-dasharray: 301px;
stroke-dashoffset: 200px;
animation: path 1.5s linear 0s infinite;
}
#keyframes path {
60% { stroke-dashoffset: 40px; }
100% { stroke-dashoffset: 200px; }
}
#keyframes rotate {
100% { transform: rotateZ(360deg) }
}
<div class="loader">
<svg viewport="0 0 100 100" preserveAspectRatio="xMidYMid meet">
<path d="M 50, 50 m -48, 0 a 48,48 0 1,0 96,0 a 48,48 0 1,0 -96,0" />
</svg>
</div>

Image between SVG

#home {
height: 100vh;
background-image: url("http://4.bp.blogspot.com/-yB6Tc3mleuE/T4NkAKeazYI/AAAAAAAACB0/tlichKzIu3Q/s1600/Simple+unique+odd+weird+wallpapers+minimalistic+%2330+battleship+titanic.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
overflow: hidden;
padding: 0;
margin-left: -10px;
}
.background {
overflow: hidden;
}
#fg {
fill: pink;
stroke: #fff;
stroke-width: 10px;
stroke-dasharray: 1024px;
-webkit-animation: dash 2s;
animation: dash 2s;
}
#keyframes dash {
from {
stroke-dashoffset: 1024px;
}
to {
stroke-dashoffset: 0px;
}
}
#-webkit-keyframes dash {
from {
stroke-dashoffset: 1024px;
}
to {
stroke-dashoffset: 0px;
}
}
#bg {
fill: white;
stroke: none;
transform-origin: 1270px 550px;
-webkit-animation: bgfill 2s linear 2s forwards;
animation: bgfill 2s linear 2s forwards;
}
#keyframes bgfill {
from {
transform: scale(1);
}
to {
transform: scale(4);
}
}
#-webkit-keyframes bgfill {
from {
transform: scale(1);
}
to {
transform: scale(4);
}
}
<div id="home" class="section" style="height:100vh;">
<div class="background">
<svg viewBox="0 0 1376 764">
<defs>
<path id="shape" d="M1034.5,770.5a125.59,125.59,0,0,0-17-32c-12.32-16.72-25.68-25.84-33-31-6-4.23-59.88-42.55-100-90-13.64-16.14-20.57-24.48-26-38-15-37.48-3.73-73.65,0-85,8.68-26.45,23-43.26,35-57,19-21.82,33.56-29.9,67-54,33.68-24.27,55.39-39.91,77-60,40.56-37.69,35.94-49.35,81-96,34.18-35.39,51.27-53.08,79-65,7.79-3.35,76-31.44,140,2a142.06,142.06,0,0,1,31,22l7.5,7.5 L 1376,770.5 Z" />
</defs>
<use xlink:href="#shape" id="bg" />
<use xlink:href="#shape" id="fg" />
</svg>
</div>
</div>
I can not seem to make the background image visible at all times while remaining the same effect, making the fill transparent gets rid of the animation, I also tried to play around with z-index on various elements but without success, how can I make it so that the background image is visible inside the white line instead of the pink svg?
I also tried applying the same image to the pink SVG as fill and it kind of works, I just can not seem to make the image appear like how it would if it was full screen, it also makes the page a bit slow:
#fg {
fill: url(#image);
stroke: #fff;
stroke-width: 10px;
stroke-dasharray: 1024px;
-webkit-animation: dash 2s;
animation: dash 2s;
}
<pattern id="image" width="1" height="1">
<image xlink:href="http://4.bp.blogspot.com/-yB6Tc3mleuE/T4NkAKeazYI/AAAAAAAACB0/tlichKzIu3Q/s1600/Simple+unique+odd+weird+wallpapers+minimalistic+%2330+battleship+titanic.jpg"></image>
</pattern>
You can get rid of the pink with fill-opacity. But you would need to adjust the white "background" as it overlays the background-image.
You might need to change the shape for that.
You could also include the image as a layer in the svg.
#home {
height: 100vh;
background-image: url("http://4.bp.blogspot.com/-yB6Tc3mleuE/T4NkAKeazYI/AAAAAAAACB0/tlichKzIu3Q/s1600/Simple+unique+odd+weird+wallpapers+minimalistic+%2330+battleship+titanic.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
overflow: hidden;
padding: 0;
margin-left: -10px;
}
.background {
overflow: hidden;
}
#fg {
fill: pink;
fill-opacity: 0;
stroke: #fff;
stroke-width: 10px;
stroke-dasharray: 1024px;
-webkit-animation: dash 2s;
animation: dash 2s;
}
#keyframes dash {
from {
stroke-dashoffset: 1024px;
}
to {
stroke-dashoffset: 0px;
}
}
#-webkit-keyframes dash {
from {
stroke-dashoffset: 1024px;
}
to {
stroke-dashoffset: 0px;
}
}
#bg {
fill: white;
opacity: .5;
stroke: none;
transform-origin: 1270px 550px;
-webkit-animation: bgfill 2s linear 2s forwards;
animation: bgfill 2s linear 2s forwards;
}
#keyframes bgfill {
from {
transform: scale(1);
}
to {
transform: scale(4);
}
}
#-webkit-keyframes bgfill {
from {
transform: scale(1);
}
to {
transform: scale(4);
}
}
<div id="home" class="section" style="height:100vh;">
<div class="background">
<svg viewBox="0 0 1376 764">
<defs>
<path id="shape" d="M1034.5,770.5a125.59,125.59,0,0,0-17-32c-12.32-16.72-25.68-25.84-33-31-6-4.23-59.88-42.55-100-90-13.64-16.14-20.57-24.48-26-38-15-37.48-3.73-73.65,0-85,8.68-26.45,23-43.26,35-57,19-21.82,33.56-29.9,67-54,33.68-24.27,55.39-39.91,77-60,40.56-37.69,35.94-49.35,81-96,34.18-35.39,51.27-53.08,79-65,7.79-3.35,76-31.44,140,2a142.06,142.06,0,0,1,31,22l7.5,7.5 L 1376,770.5 Z" />
</defs>
<use xlink:href="#shape" id="bg" />
<use xlink:href="#shape" id="fg" />
</svg>
</div>
</div>

CSS loader/Progress spinner Material angular 2+

I'm trying to imitate the loader/Progress spinner from angular material. So far I made the following component. But I don't know why the length of the dash isn't changing.
body {
background-color: white;
}
// demo-specific
.showbox {
position: absolute;
}
// end demo-specific
.loader {
position: relative;
margin: 0 auto;
width: 100px;
&:before {
content: '';
display: block;
padding-top: 100%;
}
}
.circular {
animation: rotate 2s linear infinite;
height: 100%;
transform-origin: center center;
width: 100%;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
margin: auto;
}
.path {
stroke-dasharray: 1, 200;
stroke-dashoffset: 0;
animation: dash 2s ease-in-out infinite;
stroke-linecap: round;
stroke: #0057e7;
}
#keyframes rotate {
100% {
transform: rotate(360deg);
}
}
#keyframes dash {
0% {
stroke-dasharray: 20, 200;
stroke-dashoffset: 0;
}
50% {
stroke-dasharray: 100, 200;
stroke-dashoffset: -35px;
}
100% {
stroke-dasharray: 200, 200;
stroke-dashoffset: -125px;
}
}
<div class="showbox">
<div class="loader">
<svg class="circular" viewBox="25 25 50 50">
<circle class="path" cx="50" cy="50" r="20" fill="none" stroke-width="2" stroke-miterlimit="10"/>
</svg>
</div>
</div>
The problem to me looks like it is going straight from 0% to 50%, where are the example they transition from 0% to 10% etc etc etc. Simply include more steps between 0 and 50%.