-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclip-path-circle-progress.html
115 lines (107 loc) · 2.54 KB
/
clip-path-circle-progress.html
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
html,body {
padding: 0;
margin: 0;
height: 100%;
}
body {
background-color: slategrey;
display: flex;
justify-content: center;
align-items: center;
}
.circle-box {
border-radius: 50%;
width: 160px;
height: 160px;
overflow: hidden;
position: relative;
}
.circle-box::after {
content: '';
display: block;
width: 140px;
height: 140px;
border: 20px solid rgba(255, 255, 255, .2);
border-radius: 50%;
position: absolute;
top: -10px; left: -10px;
z-index: 1;
}
.circle-box::before {
content: '';
display: block;
width: 140px;
height: 140px;
border-radius: 50%;
position: absolute;
top: 0; left: 0; bottom: 0; right: 0;
margin: auto;
z-index: 3;
background-color: yellow;
background-size: cover;
background-image: url('https://tvax3.sinaimg.cn/crop.0.0.1242.1242.180/4ca9b00fly8frote8nd02j20yi0yimyu.jpg?KID=imgbed,tva&Expires=1610009213&ssig=2ZR8j6cM1%2F');
}
.circle {
width: 140px;
height: 140px;
border: 20px solid rgb(165, 196, 226);
border-radius: 50%;
position: absolute;
top: -10px; left: -10px;
z-index: 2;
}
</style>
</head>
<body>
<div>
<div class="circle-box">
<div class="circle"></div>
</div>
<p style="text-align: center; color: white;">0%</p>
</div>
<script>
let div = document.getElementsByClassName('circle')[0];
let p = document.getElementsByTagName('p')[0];
function calc(rate){
rate = (rate + 180) * -1
let x = (Math.sin(rate * Math.PI/180) + 1) / 2
let y = (Math.cos(rate * Math.PI/180) + 1) / 2
return Math.round(x * 100) + "% " + Math.round(y * 100) + "%"
}
function endHandler() {
console.info("结束")
div = null
d = null
totalTime = null
dotData = null
p = null
}
// 角度,从0 开始
let d = 0;
// 累加的最大值
let totalTime = 10000;
// 保存的环上的点数组数据
let dotData = []
let si = setInterval(() => {
// 计算并保存当前角度的
p.innerText = (d/totalTime * 100).toFixed(0) + '%'
dotData.push(calc(d / totalTime * 360))
// 将计算的点数据赋值给页面环元素(vue写法)
// cycleCss =
// console.log(dotData)
div.style.clipPath = "polygon(50% 50%," + dotData.join(",") + ")"
if(d >= totalTime){
clearInterval(si)
endHandler()
} else {
d = d + 50;
}
}, 50)
</script>
</body>
</html>