CSS实现环形进度条

1. 利用conic-gradient 圆锥渐变        

可以看看conic-gradient()详解

   <div class="progress" ></div>
   <style>
    .progress{
      height: 170px;
      width: 170px;
      border-radius: 50%;
      background: conic-gradient(
        rgb(25, 252, 236) 36deg,
        rgba(255, 255, 255, 0.1) 36deg 170deg
      );
    }
    </style>

2.中间加一遮罩层

   <div class="progress" >
        <div class="pie"></div>
  </div>
<style>
   .progress{
      height: 170px;
      width: 170px;
      border-radius: 50%;
      background: conic-gradient(
        rgb(25, 252, 236) 36deg,
        rgba(255, 255, 255, 0.1) 36deg 170deg
      );
      display: flex;
      justify-content: center;
      align-items: center;
    }
    .pie {
        height: 145px;
        width: 145px;
        background-color: rgb(12, 41, 76);
        border-radius: 50%;
    }
</style>

3.添加动画转动效果

   <div class="progress" >
        <div class="pie"></div>
  </div>
  <style>
   @keyframes rotate {
    0% {
        transform:rotate(0deg);
    }
    25% {
        /* 基于x,y轴   (-300px) 正值向下移动 负值向上移动*/
        transform:rotate(90deg);
    }
    50% {
        transform:rotate(180deg);
    }
    75% {
        transform:rotate(270deg);
    }
    100% {
        transform:rotate(360deg);
    }
   }
   .progress{
      height: 170px;
      width: 170px;
      border-radius: 50%;
      background: conic-gradient(
        rgb(25, 252, 236) 36deg,
        rgba(255, 255, 255, 0.1) 36deg 170deg
      );
      display: flex;
      justify-content: center;
      align-items: center;
      animation-name: rotate;
      /* 关键帧动画需要的时长 */
      animation-duration: 3s;
      /* 指定关键帧动画执行的次数  infinite 无限次数*/
      animation-iteration-count: infinite;
      /* 动画执行函数  */
      animation-timing-function: linear;
    }
    .pie {
        height: 145px;
        width: 145px;
        background-color: rgb(12, 41, 76);
        border-radius: 50%;
    }
  </style>

最终效果:

动态样式:

 <div 
   class="progress" 
   :style="{
      background:`conic-gradient(rgb(25, 252, 236)${graditentLeft}deg, 
               rgba(255, 255, 255, 0.1) ${graditentLeft}deg 360deg)` }">
<div class="pie"></div>
</div>

  data() {
    return {
      graditentLeft: 360 * 0.25,
      graditentRight: 360 * 0.75,     
    };
  },

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值