JSFiddle - React, Tailwind, and code Playground
by Maayan Levy
HTML
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<div class="circle">
<div class="hold">
<div class="pie"></div>
</div>
<div class="hold2">
<div class="pie2"></div>
</div>
<div class="status"></div>
</div>
CSS
* {
margin:0;
padding:0;
}
.circle {
background-color:#ecc0b7;
width:200px;
height:200px;
-moz-border-radius:100px;
-webkit-border-radius:100px;
border-radius:100px;
position:relative;
}
.hold {
position:absolute;
top:0;
left:0;
width:200px;
height:200px;
clip:rect(0px, 200px, 200px, 100px);
}
.pie {
position:absolute;
width:200px;
height:200px;
clip:rect(0px, 100px, 200px, 0px);
-moz-border-radius:100px;
-webkit-border-radius:100px;
border-radius:100px;
background-color:#f7e5e1;
border-color:#f7e5e1;
-moz-transform:rotate(0);
-webkit-transform:rotate(0);
-o-transform:rotate(0);
transform:rotate(0);
}
.hold2 {
position:absolute;
top:0;
left:0;
width:200px;
height:200px;
clip:rect(0, 100px, 200px, 0px);
}
.pie2 {
position:absolute;
width:200px;
height:200px;
clip:rect(0px, 200px, 200px, 100px);
-moz-border-radius:100px;
-webkit-border-radius:100px;
border-radius:100px;
background-color:#f7e5e1;
border-color:#f7e5e1;
-moz-transform:rotate(0);
-webkit-transform:rotate(0);
-o-transform:rotate(0);
transform:rotate(0);
}
.status {
position:absolute;
height:30px;
width:200px;
line-height:72px;
text-align:center;
top:50%;
margin-top:-40px;
font-size:72px;
}
JavaScript
$(document).ready(function () {
progressBarUpdate(7, 8);
});
function rotate(element, degree) {
element.css({
'-webkit-transform': 'rotate(' + degree + 'deg)',
'-moz-transform': 'rotate(' + degree + 'deg)',
'-ms-transform': 'rotate(' + degree + 'deg)',
'-o-transform': 'rotate(' + degree + 'deg)',
'transform': 'rotate(' + degree + 'deg)',
'zoom': 1
});
}
function progressBarUpdate(x, outOf) {
var firstHalfAngle = 180;
var secondHalfAngle = 0;
// caluclate the angle
var drawAngle = x / outOf * 360;
// calculate the angle to be displayed if each half
if (drawAngle <= 180) {
firstHalfAngle = drawAngle;
} else {
secondHalfAngle = drawAngle - 180;
}
// set the transition
rotate($(".pie"), firstHalfAngle);
rotate($(".pie2"), secondHalfAngle);
// set the values on the text
$(".status").html(x + "/" + outOf);
}