svg 圆环进度条从0到80%效果,进度条颜色为:#1e9fff,圆环宽度为:150px,圆环的线宽为:5px
时间: 2024-03-27 07:38:48 浏览: 23
好的,以下是SVG圆环进度条的代码,可以实现从0到80%的效果,进度条颜色为#1e9fff,圆环宽度为150px,圆环的线宽为5px:
```html
<svg viewBox="0 0 220 220">
<defs>
<linearGradient id="gradient" x1="0" y1="0" x2="1" y2="1">
<stop offset="0%" stop-color="#1e9fff" />
<stop offset="80%" stop-color="#1e9fff" />
<stop offset="80%" stop-color="#fff" />
</linearGradient>
<mask id="mask">
<rect x="0" y="0" width="100%" height="100%" fill="#fff"/>
<circle cx="110" cy="110" r="75" stroke="#000" stroke-width="5"/>
<circle id="progress" cx="110" cy="110" r="75" stroke="url(#gradient)" stroke-width="5" stroke-dasharray="471" stroke-dashoffset="471" transform="rotate(-90,110,110)"/>
</mask>
</defs>
<rect x="0" y="0" width="100%" height="100%" fill="#fff" mask="url(#mask)"/>
</svg>
```
解释一下代码:
- `viewBox="0 0 220 220"`:设置SVG的视图盒子大小。
- `linearGradient`:定义一个线性渐变,从#1e9fff到#fff,从左上角到右下角。
- `mask`:定义一个蒙版,用于遮罩。
- `rect`:在蒙版上绘制一个矩形,用于遮罩。
- `circle`:在蒙版上绘制两个圆,一个圆用于绘制圆环,另一个圆用于遮罩。其中,第一个圆的stroke为#000,stroke-width为5,用于绘制圆环的边框;第二个圆的stroke为线性渐变,stroke-width为5,stroke-dasharray为471(圆周长,2*pi*r),stroke-dashoffset为471,transform为rotate(-90,110,110),用于绘制圆环进度条。
你可以将代码复制到HTML文件中,用浏览器打开即可看到效果。