-
Notifications
You must be signed in to change notification settings - Fork 0
/
stars.html
123 lines (115 loc) · 2.79 KB
/
stars.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stars</title>
</head>
<style>
* {
margin: 0;
padding: 0;
overflow: hidden;
}
.main {
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.circle {
width: 100px;
height: 100px;
border-radius: 50%;
background-color: black;
transition: 0.5s ease-in-out;
}
.bouncy {
animation: bounce 0.5s ease-in infinite alternate;
}
.star {
width: 5px;
height: 5px;
position: absolute;
background-color: black;
border-radius: 50%;
}
.s1 {
animation: still 0.7s ease-in-out infinite alternate;
}
.s2 {
animation: shine 1.4s ease-in-out infinite alternate;
}
.s3 {
animation: shine 2.1s ease-in-out infinite alternate;
}
.s4 {
animation: shine1 2.8s ease-in-out infinite alternate;
}
.s5 {
animation: shine1 3.5s ease-in-out infinite alternate;
}
.s6 {
animation: shine1 4.2s ease-in-out infinite alternate;
}
@keyframes bounce {
from {
margin-bottom: 60px;
}
to {
margin-bottom: 0px;
}
}
@keyframes shine {
from {
background-color: black;
}
to {
background-color: white;
box-shadow: 0 0 5px 5px #1b094d;
}
}
</style>
<body>
<div class="main">
<div class="circle bouncy" id="circle"></div>
</div>
</body>
<script>
let circle = document.getElementById("circle");
let options = ["s1", "s2", "s3", "s4", "s5", "s6"];
let c = 0;
circle.addEventListener("click", () => {
c += 1;
circle.classList.remove("bouncy");
circle.style.width = "100vw";
circle.style.height = "100vh";
circle.style.borderRadius = "0px";
if (c == 1) {
setTimeout(() => {
for (let i = 0; i <= 1000; i++) {
addRandomStar();
}
}, 2000);
} else {
return;
}
});
function addRandomStar() {
let s = document.createElement("div");
s.style.marginTop = getRandomTop().toString() + "px";
s.style.marginLeft = getRandomRight().toString() + "px";
s.classList.add("star");
s.classList.add(options[Math.ceil(Math.random() * options.length) - 1]);
circle.appendChild(s);
}
function getRandomTop() {
return Math.ceil(Math.random() * 15 * parseInt(circle.style.height));
}
function getRandomRight() {
return Math.ceil(Math.random() * 15 * parseInt(circle.style.width));
}
</script>
</html>