<center><h1>CSS Radial Chart / Progress</h1></center>
<!--Created by Rodrigo Portillo-->
<!--https://velhobit.com.br-->
<div class="area">
<!--This is the Structure of your chart-->
<div class="chart">
<div class="radio_chart" id="radioChartContent">
</div>
<div class="cap">
</div>
<div class="value" id="percentValue">
0%
</div>
</div>
</div>
<!--This is just the example buttons-->
<div class="area">
<button onclick="goTo(80)">
Go To 80%
</button>
<button onclick="goTo(20)">
Go To 20%
</button>
<button onclick="goTo(100)">
Full
</button>
<button onclick="reset()">
Reset
</button>
</div>
/**
* This function allows you to go to an specific frame of the animation
* Remember the frames are a percentage number, so it goes from 0 to 100
**/
function goTo(frame){
reset(); // Just reset
//For some reason Javascript needs a time to remove animate class. I tried to use as callback from reset but it just didnt work.
setTimeout(function(){
//Get components
var chart = document.getElementById("radioChartContent"), pVal = document.getElementById("percentValue");
//Add animate
chart.classList.add("animate");
var currentPercent = 0; //Initial percentage
//Get percentage one by one
var currTimeout = setInterval(function(){
//Check is reach the limit
if(currentPercent == frame || currentPercent > 100){
//Clear interval
clearInterval(currTimeout);
//Pause animation
chart.style.animationPlayState = "paused";
chart.style.webkitAnimationPlayState = "paused"; //if webkit
return false;
}else{
//Sum percentage
currentPercent++;
//show new percentage
pVal.innerHTML = currentPercent+"%";
}
}, 10); //We are using 10 cause it reference by a 1 second (1000 miliseconds) animation. If you're using 4 seconds, change to 40 as example
},100);
}
//Reset to initial position
function reset(){
var chart = document.getElementById("radioChartContent"), pVal = document.getElementById("percentValue");
chart.classList.remove("animate");
pVal.innerHTML = "0%";
chart.style.animationPlayState = "initial";
chart.style.webkitAnimationPlayState = "initial"; //if webkit
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.