JSFiddle - React, Tailwind, and code Playground

by nikolya223

HTML

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<div class="pie pie-1">
    <div class="clip1">
        <div class="slice1"></div>
    </div>
    <div class="clip2">
        <div class="slice2"></div>
    </div>
    <div class="status"></div>
</div>
<div class="pie pie-2">
    <div class="clip1">
        <div class="slice1"></div>
    </div>
    <div class="clip2">
        <div class="slice2"></div>
    </div>
    <div class="status"></div>
</div>
<div class="pie pie-3">
    <div class="clip1">
        <div class="slice1"></div>
    </div>
    <div class="clip2">
        <div class="slice2"></div>
    </div>
    <div class="status"></div>
</div>

CSS

@import url(http://fonts.googleapis.com/css?family=Titillium+Web:400,700);
.pie{
    background-color:#DFE8ED;
    width:160px;
    height:160px;
    -moz-border-radius:100%;
    -webkit-border-radius:100%;
    border-radius:100%;
    position:relative;
}
.clip1 {
    position:absolute;
    top:0;
    left:0;
    width:160px;
    height:160px;
    clip:rect(0px, 160px, 160px, 80px);
}
.slice1 {
    position:absolute;
    width:160px;
    height:160px;
    clip:rect(0px, 80px, 160px, 0px);
    -moz-border-radius:100%;
    -webkit-border-radius:100%;
    border-radius:100%;
    background-color:#30BAE7;
    border-color:#30BAE7;
    -moz-transform:rotate(0);
    -webkit-transform:rotate(0);
    -o-transform:rotate(0);
    transform:rotate(0);
}
.clip2 {
    position:absolute;
    top:0;
    left:0;
    width:160px;
    height:160px;
    clip:rect(0, 80px, 160px, 0px);
}
.slice2 {
    position:absolute;
    width:160px;
    height:160px;                                /*<- вот здесь была ошибка*/
    clip:rect(0px, 160px, 160px, 80px);
    -moz-border-radius:100%;
    -webkit-border-radius:100%;
    border-radius:100%;
    background-color:#30BAE7;
    border-color:#30BAE7;
    -moz-transform:rotate(0);
    -webkit-transform:rotate(0);
    -o-transform:rotate(0);
    transform:rotate(0);
}
.status {
    
    position:absolute;
    top:13px;
    left: 13px;
    width: 134px;
    height: 93px;
    padding-top: 41px;
    border-radius: 100%;
    font-family: 'Titillium Web', sans-serif;
    font-size:50px;
    text-align:center;
    color: #3C4761;
    line-height:50px;
    background: #fff;
}

JavaScript

$(document).ready(function () {
    var pie1 = $('.pie-1'),
        pie2 = $('.pie-2'),
        pie3 = $('.pie-3');
    progressBarUpdate(10, 100, pie1);
    progressBarUpdate(65, 100, pie2);
    progressBarUpdate(100, 100, pie3);
});

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, elem) {
    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(elem.find(".slice1"), firstHalfAngle);
    rotate(elem.find(".slice2"), secondHalfAngle);

    // set the values on the text
    elem.find(".status").html(x + "<span>%</span>");
}