HTML+CSS+jquery 实现环形比例图效果 AngularJS+css实现环形比例图效果

                 1.HTML+CSS+jquery 实现环形比例图效果

  2.AngularJS+css实现环形比例图效果




1.  HTML+CSS+jquery 实现环形比例图效果

HMTL代码

[html]  view plain  copy
  1. <!doctype html>  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">  
  5. <title>百分比</title>  
  6. <style type="text/css">  
  7. .yuan{ width:200px; height:200px; margin:0 auto; box-sizing:border-box; padding-top:20px; text-align:center; background-color:#f1f1f1; border-radius:50%; position:relative;}  
  8. .yuan_bl1 , .yuan_bl2 , .yuan_bl3 , .yuan_bl4{ width:100%; height:100%; border-radius:50%; position:absolute; left:0; top:0;}  
  9. .yuan_bl1 , .yuan_bl2{ background-color:#FF7F4C; -webkit-box-shadow:0 0 1px 1px #fff inset; box-shadow:0 0 1px 1px #fff inset;}  
  10. .yuan_bl3 , .yuan_bl4{ background-color:#f1f1f1;}  
  11. .yuan_bl1 , .yuan_bl3{ clip:rect(0 200px 100px 0);}  
  12. .yuan_bl2 , .yuan_bl4{ clip:rect(100px 200px 200px 0);}  
  13. .yuan_text{ width:160px; height:160px; line-height:160px; box-sizing:border-box; padding-left:10px; margin:0 auto; color:#FF7F4C; font-size:36px; font-family:"PingFangSC-Thin","sans-serif","STHeitiSC-Light","微软雅黑","Microsoft YaHei"; background-color:#fff; border-radius:50%; position:relative;}  
  14. </style>  
  15. <script type="text/javascript" src="jquery.js"></script>  
  16. </head>  
  17. <body>  
  18. <div class="yuan">  
  19.     <div class="yuan_bl1"></div>  
  20.     <div class="yuan_text">81°</div>  
  21. </div>  
  22. <script>  
  23. $(function(){  
  24.     //初始化  
  25.     var bl = parseInt($('.yuan_text').html());  
  26.     var rotatenum = bl;  
  27.     if(bl > 180){  
  28.         var blhtml = '';  
  29.         rotatenum = bl - 180;  
  30.         blhtml += '<div class="yuan_bl2">';  
  31.         blhtml += '<div class="yuan_bl4" style="-webkit-transform:rotate(' + rotatenum + 'deg);transform:rotate(' + rotatenum + 'deg);"></div>';  
  32.         blhtml += '</div>';  
  33.         //$('.yuan_bl1').remove($('.yuan_bl3'));  
  34.         $('.yuan_bl1').after(blhtml);  
  35.     }else{  
  36.         var blhtml = '';  
  37.         blhtml += '<div class="yuan_bl3" style="-webkit-transform:rotate(' + rotatenum + 'deg);transform:rotate(' + rotatenum + 'deg);"></div>';  
  38.         $('.yuan_bl1').append(blhtml);  
  39.     }  
  40. })  
  41. </script>  
  42. </body>  
  43. </html>  
<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>百分比</title>
    <style type="text/css">
        .yuan{ width:200px; height:200px; margin:0 auto; box-sizing:border-box; padding-top:20px; text-align:center; background-color:#f1f1f1; border-radius:50%; position:relative;}
        .yuan_bl1 , .yuan_bl2 , .yuan_bl3 , .yuan_bl4{ width:100%; height:100%; border-radius:50%; position:absolute; left:0; top:0;}
        .yuan_bl1 , .yuan_bl2{ background-color:#1585ff; -webkit-box-shadow:0 0 1px 1px #fff inset; box-shadow:0 0 1px 1px #fff inset;}
        .yuan_bl3 , .yuan_bl4{ background-color:#f1f1f1;}
        .yuan_bl1 , .yuan_bl3{ clip:rect(0 200px 200px 100px);}
        .yuan_bl2 , .yuan_bl4{ clip:rect(0 100px 200px 0);}
        .yuan_text{ width:180px; height:180px;  line-height:180px; box-sizing:border-box; padding-left:5px; margin:-10px auto; color:#1585ff; font-size:36px; font-family:"PingFangSC-Thin","sans-serif","STHeitiSC-Light","微软雅黑","Microsoft YaHei"; background-color:#fff; border-radius:50%; position:relative;}
    </style>
    <script type="text/javascript" src="js/jquery.js"></script>
</head>
<body>
<div class="yuan">
   <div class="yuan_bl1">
      <div class="yuan_bl3" style="-webkit-transform:rotate(50deg);transform:rotate(50deg);"></div>

    </div>
   <!-- <div class="yuan_bl2">
    <div class="yuan_bl4" style="-webkit-transform:rotate(30deg);transform:rotate(30deg);"></div>
    </div>-->
    <div class="yuan_text">270.8°</div>
</div>
<script>
   /* $(function(){
        //初始化
        var bl = parseInt($('.yuan_text').html());
        var rotatenum = bl;
        if(bl > 180){
            var blhtml = '';
            rotatenum = bl - 180;
            blhtml += '<div class="yuan_bl2">';
            blhtml += '<div class="yuan_bl4" style="-webkit-transform:rotate(' + rotatenum + 'deg);transform:rotate(' + rotatenum + 'deg);"></div>';
            blhtml += '</div>';
            //$('.yuan_bl1').remove($('.yuan_bl3'));
            $('.yuan_bl1').after(blhtml);
        }else{
            var blhtml = '';
            blhtml += '<div class="yuan_bl3" style="-webkit-transform:rotate(' + rotatenum + 'deg);transform:rotate(' + rotatenum + 'deg);"></div>';
            $('.yuan_bl1').append(blhtml);
        }
    })*/
</script>
</body>
</html>
  2.AngularJS+css实现环形比例图效果

代码:

        <div class="hlyw-yh-r">
           <div class="hlyw-yuanhuan">
               <div class="yuan">
                   <div class="yuan_bl1">
                      <div ng-if="(x.discRate|number:1)*3.6<180" class="yuan_bl3" style="-webkit-transform:rotate({{x.discRate*3.6}}deg);transform:rotate({{x.discRate*3.6}}deg);"></div>

                   </div>
                   <div class="yuan_bl2" ng-if="(x.discRate|number:1)*3.6>180">
                       <div class="yuan_bl4" style="-webkit-transform:rotate({{x.discRate*3.6-180}}deg);transform:rotate({{x.discRate*3.6-180}}deg);"></div>
                   </div>
                   <div class="yuan_text">{{x.discRate|number:1}}<span class="span-color-size-L">%</span></div>
               </div>
           </div>
         <div class="hlyw-yuanhuan-x">
             离散率
         </div>
        </div>
.hlyw-yh-r{
    width:80px;
    height: 105px;
    float: left;
}
.hlyw-yuanhuan{
    width:80px;
    height: 80px;
}
.hlyw-yuanhuan-x{
    width:80px;
    height: 25px;
    text-align: center;
    line-height: 25px;
    font-size: 18px;
    color: #8c8c9d;
}

/* div 百分比圆环*/
.yuan{ width:80px; height:80px; margin:0 auto; box-sizing:border-box; padding-top:20px; text-align:center; background-color:#f1f1f1; border-radius:50%; position:relative;}
.yuan_bl1 , .yuan_bl2 , .yuan_bl3 , .yuan_bl4{ width:100%; height:100%; border-radius:50%; position:absolute; left:0; top:0;}
.yuan_bl1 , .yuan_bl2{ background-color:#1585ff; -webkit-box-shadow:0 0 1px 1px #fff inset; box-shadow:0 0 1px 1px #fff inset;}
.yuan_bl3 , .yuan_bl4{ background-color:#f1f1f1;}
.yuan_bl1 , .yuan_bl3{ clip:rect(0 80px 80px 40px);}
.yuan_bl2 , .yuan_bl4{ clip:rect(0 40px 80px 0);}
.yuan_text{ width:62px; height:62px;  line-height:62px; box-sizing:border-box; padding-left:5px; margin:-10px auto; color:#1585ff; font-size:18px; font-family:"PingFangSC-Thin","sans-serif","STHeitiSC-Light","微软雅黑","Microsoft YaHei"; background-color:#fff; border-radius:50%; position:relative;}







猜你喜欢

转载自blog.csdn.net/zhangyufeng0126/article/details/78031236