-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
38 lines (30 loc) · 922 Bytes
/
script.js
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
const MIN_SIZE = 10;
const MAX_SIZE = 20;
const MIN_DURATION = 2000;
const MAX_DURATION = 5000;
const snowflakesContainer = document.getElementById("snowflakes-container");
setInterval(() => createSnowflake(), 50);
function randint(lo, hi) {
return Math.random() * (hi - lo) + lo;
}
function randomIcon() {
if (Math.random() < 0.5) {
return "fa-snowflake";
} else {
return "fa-tint";
}
}
function createSnowflake() {
const snowFlake = document.createElement("i");
snowFlake.classList.add("fas", randomIcon());
snowFlake.style.left = randint(0, 100) + "%";
snowFlake.style.opacity = Math.random();
snowFlake.style.fontSize = randint(MIN_SIZE, MAX_SIZE) + "px";
snowflakesContainer.appendChild(snowFlake);
snowFlake
.animate(
{ transform: `translate(0vw, 100vh)` },
{ duration: randint(MIN_DURATION, MAX_DURATION) }
)
.finished.then(() => snowFlake.remove());
}