纯CSS实现圆形进度条
在css3中为我们提供了背景渐变(gradients)属性,通过这个属性我们可以实现多个颜色的平滑过渡。
常使用的渐变方式有:线性渐变linear-gradients和径向渐变radial-gradients,这里使用的不是这两种方式而是圆锥渐变conic-gradient,圆锥渐变的效果如下:

实现代码:
background: conic-gradient(red, orange, yellow, green, blue);
background: conic-gradient(
red 6deg, orange 6deg 18deg, yellow 18deg 45deg,
green 45deg 110deg, blue 110deg 200deg, purple 200deg);
background: conic-gradient(from 3.1416rad at 10% 50%, #e66465, #9198e5);
1
2
3
4
5
2
3
4
5
conic-gradient接收多个参数,首个参数为from a to b(可缺省),a代表颜色起始角度、b代表中心点位置(百分比或px),后面跟若干个颜色值,颜色值可以搭配所占角度或百分比
根据上面的原理,如果只存在两种颜色并以圆环截取其中内容就会得到进度条

代码如下:
<template>
<div class="con">
<!-- 定义data-value用于css中content变量使用 -->
<div class="circle" :data-value="value" :style="{background: 'conic-gradient(rgba(0,255,255,1) ' + percent + ', rgba(0,255,255,.2) 0)'}"></div>
<div class="options">
<div class="add" @click="value < 100 && value++">+</div>
<div class="sub" @click="value > 0 && value--">-</div>
</div>
</div>
</template>
<script>
export default {
data() {
return {
value: 10,
total: 100,
}
},
computed: {
percent() {
return ((this.value / this.total) * 100).toFixed(2) + '%'
}
}
}
</script>
<style scoped lang="scss">
.con {
display: flex;
flex-direction: row;
align-items: center;
.circle {
position: relative;
width: 100px;
height: 100px;
border-radius: 50%;
transition: .3s linear;
&::before {
content: attr(data-value);
position: absolute;
left: 0;
top: 0;
right: 0;
bottom: 0;
margin: auto;
display: flex;
align-items: center;
justify-content: center;
width: 90px;
height: 90px;
border-radius: 50%;
background: white;
}
}
.circle-no-blank {
position: relative;
width: 100px;
height: 100px;
margin: 0 30px;
border-radius: 50%;
transition: .3s linear;
}
.circle-concentric {
position: relative;
width: 100px;
height: 100px;
margin: 0 30px;
border-radius: 50%;
transition: .3s linear;
}
.options {
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-around;
height: 100px;
margin-left: 20px;
.add,.sub {
width: 25px;
height: 25px;
line-height: 25px;
text-align: center;
border: 1px solid #999999;
border-radius: 50%;
cursor: pointer;
}
}
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
简单修改上面代码,将纯色进度变为渐变进度:
<div class="circle" :data-value="value" :style="{background: 'conic-gradient(rgba(0,255,255,1), rgba(0,255,255,0) ' + percent + ', rgba(0,255,255,.2) ' + percent + ')'}"></div>
1
上次更新: 2025/09/05, 8:09:00