CSS圆环百分比DEMO

<html>
<head>
<title>test</title>
<!--本DEMO参考http://www.cnblogs.com/jr1993/p/4677921.html设计,实现传入百分比数值,通过JS计算按百分比显示圆环图形功能-->
<style type="text/css"> .circleProgress_wrapper{ width: 200px; height: 200px; margin: 50px auto; position: relative; border:1px solid #ddd; } .wrapper{ width: 100px; height: 200px; position: absolute; top:0; overflow: hidden; } .right{ right:0; } .left{ left:0; } .circleProgress{ width: 160px; height: 160px; border:20px solid transparent; border-radius: 50%; position: absolute; top:0; -webkit-transform: rotate(45deg); } .rightcircle{ border-top:20px solid #ccc; border-right:20px solid #ccc; border-left:20px solid #ccc; border-bottom:20px solid #ccc; right:0; } .leftcircle{ border-bottom:20px solid #ccc; border-left:20px solid #ccc; border-top:20px solid #ccc; border-right:20px solid #ccc; left:0; } .percent { position: absolute; top: 90; left: 85; } </style> </head> <body> <div class="circleProgress_wrapper"> <div class="wrapper right"> <div class="circleProgress rightcircle"></div> </div> <div class="wrapper left"> <div class="circleProgress leftcircle"></div> </div> <span class="percent" int-percent='100'>100%</span> </div> </body> </html> <script type="text/javascript" src="jquery-1.8.3.min.js" ></script> <script> var deg = {percent:100,left:225,leftBC:"#ccc",right:225,rightBC:"#ccc"}; var pint; $(function(){ loadPercent($(".percent").attr("int-percent")); pint = setInterval("refreshPercent()",100); }); function refreshPercent() { var percent = $(".percent").attr("int-percent"); if (percent>0) { percent--; } else if (percent == 0){ percent = 100; } $(".percent").attr("int-percent",percent); $(".percent").html(percent+"%"); if (percent==48) { window.clearInterval(pint); } deg.percent=percent; loadPercent(percent); } function loadPercent(percent) { var allDeg = countDegByPercent(percent); if (allDeg>=180) { var tmpDeg = allDeg - 180; deg.left=45+tmpDeg; deg.right=225 deg.leftBC="green"; deg.rightBC="green"; } else { deg.right=45+allDeg; deg.rightBC="green"; deg.leftBC="#ccc"; } console.log(deg); $(".circleProgress.rightcircle").css({"-webkit-transform":"rotate("+deg.right+"deg)","border-left":"20px solid "+deg.rightBC,"border-bottom":"20px solid "+deg.rightBC}); $(".circleProgress.leftcircle").css({"-webkit-transform":"rotate("+deg.left+"deg)","border-top":"20px solid "+deg.leftBC,"border-right":"20px solid "+deg.leftBC}); } function countDegByPercent(percent) { return percent*3.6; } </script>

 

转载于:https://www.cnblogs.com/justbeginning/p/7231000.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值