image.png

  1. .pie{
  2. width: 100px;
  3. height: 100px;
  4. border-radius: 50%;
  5. background: orangered;
  6. margin: 100px;
  7. background-image: linear-gradient(to right,transparent 50%, yellow 0);
  8. }
  9. 覆盖

1 transform 的解决方案

image.png

  1. .pie{
  2. width: 100px;
  3. height: 100px;
  4. border-radius: 50%;
  5. background: orangered;
  6. margin: 100px;
  7. background-image: linear-gradient(to right,transparent 50%, yellow 0);
  8. }
  9. .pie::before{
  10. content: "";
  11. display: block;
  12. margin-left: 50%;
  13. height: 100%;
  14. background-color: inherit;
  15. transform-origin: left;/*绕着圆形的圆心来旋转 */
  16. border-radius: 0 100% 100% 0/50%;
  17. transform: rotate(72deg);
  18. }

2 动画解决

  1. 动画必须处于暂停状态。跟常规情形下我们让动画动起来的做法不一样,这里我们要用负的动画延时来直接跳至动画中的任意时间点

image.png

  1. 动画实现饼图(含百分比)
  2. <style>
  3. .pie{
  4. width: 100px;
  5. height: 100px;
  6. line-height: 100px;
  7. border-radius: 50%;
  8. background: orangered;
  9. margin: 100px;
  10. position: relative;
  11. text-align: center;
  12. color: transparent;
  13. background-image: linear-gradient(to right,transparent 50%, yellowgreen 0);
  14. }
  15. .pie::before{
  16. content: "";
  17. display: block;
  18. position: absolute;
  19. top: 0;
  20. left: 50%;
  21. /* margin-left: 50%; */
  22. height: 100%;
  23. width: 50%;
  24. background-color: inherit;
  25. transform-origin: left;/*绕着圆形的圆心来旋转 */
  26. border-radius: 0 100% 100% 0/50%;
  27. animation: spin 50s linear infinite,
  28. bg 100s step-end infinite;
  29. animation-play-state: paused;
  30. animation-delay: inherit;
  31. }
  32. @keyframes spin{
  33. to{
  34. transform: rotate(180deg);
  35. }
  36. }
  37. @keyframes bg{
  38. 50%{
  39. background: yellowgreen;
  40. }
  41. }
  42. </style>
  43. </head>
  44. <body>
  45. <div class="pie" style="animation-delay:-20s;">20%</div>
  46. <div class="pie" style="animation-delay:-60s;">60%</div>
  47. </body>

3 SVG 解决方案

image.png

  <style>
        circle{
            fill: greenyellow;
            stroke: #655;
            stroke-width: 30;
        }
    </style>

<body>
   <svg width="100" height="100">
       <circle r="30" cx="50" cy="50" />
   </svg>
</body>


fill:填充色
stroke:描边色
stroke-width:边框宽度

image.png

 stroke-dasharray: 20 10;

 stroke-dasharray 虚线描边  

 虚线的线段长度为 20 且间隙长度为 10,

image.png

    <style>
        circle{
            fill: greenyellow;
            stroke: #655;
            stroke-width: 50;
            stroke-dasharray: 60 158;
        }
        svg{
            transform: rotate(-90deg);
            background: greenyellow;
            border-radius: 50%;
            margin: 100px;
        }
    </style>
<body>
    <svg width="100" height="100">
        <circle r="25" cx="50" cy="50" />
    </svg>
</body

4 角向渐变实现

image.png

background: conic-gradient(pink 20%,lightblue 0,lightblue 30%,yellowgreen 0);