-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
140 lines (122 loc) · 3.63 KB
/
index.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<html>
<head>
<title>JS-Revision</title>
<link rel="stylesheet"
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200" />
</head>
<style>
body {
overflow: hidden;
}
.container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
width: 100vw;
overflow: hidden;
}
.animate_round {
height: 30%;
width: 30%;
animation: spin 5s linear infinite;
position: relative;
}
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.circle {
--transition-speed : 500ms;
--transition-delay : 150ms;
border-radius: 100%;
width: 25px;
height: 25px;
background-color: aqua;
transition-duration: var(--transition-speed);
transition-delay: var(--transition-delay);
}
.btn {
padding: 2px;
z-index: 10;
}
.float {
--move: 0%;
position: absolute;
top: calc(45% + var(--move));
left: calc(45% + var(--move));
}
.material-symbols-outlined {
font-variation-settings:
'FILL' #EAC452,
'wght' 400,
'GRAD' 0,
'opsz' 24
}
.first_star{
transition-duration: calc(var(--transition-speed) + 10ms);
transition-delay: calc(var(--transition-delay) + 5ms);
}
.second_star{
transition-duration: calc(var(--transition-speed) + 20ms);
transition-delay: calc(var(--transition-delay) + 10ms);
}
.third_star{
transition-duration: calc(var(--transition-speed) + 30ms);
transition-delay: calc(var(--transition-delay) + 15ms);
}
.fourth_star{
transition-duration: calc(var(--transition-speed) + 40ms);
transition-delay: calc(var(--transition-delay) + 20ms);
}
</style>
<body>
<div class="container">
<div class="animate_round">
<div class="circle float"></div>
<!-- <div class="glitter">
<span class="first_star material-symbols-outlined float">star</span>
<span class="second_star material-symbols-outlined float">star</span>
<span class="third_star material-symbols-outlined float">star</span>
<span class="fourth_star material-symbols-outlined float">star</span >
</div> -->
</div>
</div>
<button class="btn start">Start</button>
<button class="btn stop">Stop</button>
<script>
const circle = document.querySelector(".circle");
const start = document.querySelector(".start");
const stop = document.querySelector(".stop");
function setMove(dist) {
circle.style.setProperty("--move", `${dist}%`);
}
const arr = [10, 0];
var i = -1;
var id;
var isAnimating = false;
let lastTime = 0;
const delay = 500;
start.addEventListener("click", () => {
id = window.requestAnimationFrame(animate);
isAnimating = true;
})
stop.addEventListener("click", () => {
window.cancelAnimationFrame(id);
isAnimating = false;
})
function animate(currentTime) {
if (currentTime - lastTime > delay) {
i = (i + 1) % 2;
setMove(arr[i]);
lastTime = currentTime;
}
id = window.requestAnimationFrame(animate);
}
</script>
</body>
</html>