You can read this article and see a working example and even understand how css-pie-timer works.
UPDATE
I did not like this solution, so I tried to implement it myself and with a little help (I asked a few questions here). I manage to do it quite elegantly.
The basic idea is to figure out how to draw a sector of a circle, and then start drawing a section with degree = 0 until you reach the desired degree.
I also made it reversible, just for fun :).
HTML
<div class="container"> <div id="activeBorder" class="active-border"> <div id="circle" class="circle"> <span class="prec 270" id="prec">0%</span> </div> </div> </div>
The active border will be replaced by the current percentage. The preliminary range will contain the text percentage as well as the total degrees you want (270) in this example. When I implemented it, the percentage should be second grade.
CSS
This is the hard part. This is the hard part. I draw a sector this way:
.active-border{ position: relative; text-align: center; width: 110px; height: 110px; border-radius: 100%; background-color:#39B4CC; background-image: linear-gradient(91deg, transparent 50%, #A2ECFB 50%), linear-gradient(90deg, #A2ECFB 50%, transparent 50%); }
Explanation: the first linear-gradient value will be shown in degrees + 90. If the degrees are greater than 180, we will set the first linear-gradient color to our active color.
JQuery
function loopit(dir){ // choose direction if (dir == "c") i++ else i--; // stop condition if (i < 0) i = 0; if (i > degs) i = degs; // calculate and set the percentage text prec = (100*i)/360; $(".prec").html(Math.round(prec)+"%"); if (i<=180){ activeBorder.css('background-image','linear-gradient(' + (90+i) + 'deg, transparent 50%, #A2ECFB 50%),linear-gradient(90deg, #A2ECFB 50%, transparent 50%)'); } else{ activeBorder.css('background-image','linear-gradient(' + (i-90) + 'deg, transparent 50%, #39B4CC 50%),linear-gradient(90deg, #A2ECFB 50%, transparent 50%)'); } // recursive call setTimeout(function(){ if($("#circle").is(":hover")) loopit("c"); else loopit("nc"); },1); }
And here is a working demo
Note This works for firefox and chrome. You need to add IE support for linear-gradient .