SVG进度条

<svg viewBox="0 0 500 500">
  <circle cx="250" cy="250" r="200" stroke-width="50" stroke="#eee" fill="none" />
  <circle id="circle" cx="250" cy="250" r="200" stroke="url(#grad1)" stroke-width="50" fill="none" stroke-linecap="round" />
  <linearGradient id="grad1" x1="0%" y1="0%" x2="100%" y2="0%">
    <stop offset="0%" stop-color="#00F260" />
    <stop offset="100%" stop-color="#0575E6" />
  </linearGradient>
  <text id="text" x="250" y="280" fill="#0575E6">90%</text>
  <circle id="point" cx="250" cy="250" r="200" stroke-dashoffset="1256px" stroke-dasharray="1256px" stroke-linecap="round" stroke-width="40" stroke="#fff" fill="none" />
</svg>
<input id="input" type="number" min="1" max="100" value="90" />
*{margin: 0; padding: 0;}
circle{
  transform-origin: 250px 250px;
  transform: rotate(-90deg);
}
circle#circle{
  /* 周长 1256 */
  stroke-dasharray: 1130.4px 125.6px; 
  transition: stroke-dasharray 0.3s;
}
circle#point{
  transform: rotate(234deg);
  transition: transform 0.3s;
}
text{
  font-size: 100px;
  font-weight: bold;
  text-anchor: middle;
}
let _input = document.getElementById('input');
_input.addEventListener('change', function(e){
  document.getElementById('circle').style.strokeDasharray = 12.56 * e.target.value + 'px ' + 12.56*(100-e.target.value) + 'px';
  document.getElementById('text').textContent = e.target.value + "%";
  document.getElementById('point').style.transform = "rotate(" +  (e.target.value * 3.6 - 90 ) + "deg)";
})

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值