利用
css的transform来实现圆圈进度条
主要是利用了其半遮挡 的原理。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>圆边</title>
<style type="text/css" media="screen">
.circle-press-box {
overflow: hidden;
display: block;
width: 200px;
height: 200px;
background-color: transparent;
margin: auto;
position: relative;
}
.circle-box {
box-sizing: border-box;
display: block;
border-radius: 50%;
width: 100%;
height: 100%;
border: 20px solid red;
}
.left-bg {
box-sizing: border-box;
position: absolute;
width: 100%;
height: 100%;
top: 0;
transform: rotate(0deg);
border-left: 100px solid #fff;
}
.right-bg {
box-sizing: border-box;
position: absolute;
width: 100%;
height: 100%;
top: 0;
transform: rotate(0deg);
border-right: 100px solid #fff;
}
.big-half-box {
position: absolute;
top: 0;
width: 100%;
height: 100%;
display: none;
transform: rotate(0deg);
}
.half-box {
position: absolute;
top: 0;
right: 0;
overflow: hidden;
width: 50%;
height: 100%;
}
.half-circle {
box-sizing: border-box;
position: absolute;
top: 0;
right: 0;
border-radius: 50%;
width: 200%;
height: 100%;
border: 20px solid red;
}
.text-box {
position: absolute;
width: 100%;
height: 100%;
top: 0;
text-align: center;
line-height: 200px;
}
</style>
</head>
<body>
<div class="circle-press-box">
<div class="circle-box"></div>
<div class="left-bg"></div>
<div class="right-bg"></div>
<div class="big-half-box">
<div class="half-box">
<div class="half-circle"></div>
</div>
</div>
<div class="text-box">
123
</div>
</div>
<script src="js/jquery-1.7.2.js"></script>
<script type="text/javascript">
$(function() {
var r_val = 0;
setInterval(function() {
r_val+=1;
r_val=r_val%360;
console.log(r_val);
if (r_val>=180) {
$('.big-half-box').css({'display':'block','transform': 'rotate(' +(r_val-180)+ 'deg)'});
}else{
$('.right-bg').css('transform', 'rotate(' + r_val + 'deg)');
$('.big-half-box').css('display','none');
}
$('.text-box').text(parseInt((r_val/360).toFixed(2)*100)+'%');
}, 30);
});
</script>
</body>
</html>