-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsnow.js
40 lines (30 loc) · 934 Bytes
/
snow.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
39
40
const body = document.querySelector("body");
const randomPosition = () => {
return Math.random() * 99;
}
const randomSize = () => {
return Math.random() * 2.5 + 5;
}
const createSnow = () => {
const snow = document.createElement("div");
const size = randomSize();
snow.style.backgroundColor = "#fff";
snow.style.width = `${size}px`;
snow.style.height = `${size}px`;
snow.style.borderRadius = "100%";
snow.style.position = "absolute";
snow.style.top = "10px";
snow.style.left = `${randomPosition()}%`;
body.append(snow);
return snow;
}
const moveSnow = (snow) => {
setInterval(() => {
const currentPosition = parseFloat(snow.style.top);
snow.style.top = `${currentPosition + 10}px`;
if(currentPosition >= body.offsetHeight - 10) {
snow.style.display = "none";
}
}, 100);
}
setInterval(() => moveSnow(createSnow()), 250);