-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnow.js
More file actions
30 lines (20 loc) · 994 Bytes
/
snow.js
File metadata and controls
30 lines (20 loc) · 994 Bytes
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
document.addEventListener('DOMContentLoaded', () => {
const zoomFactor = 0.8;
function createSnowflake() {
const snowflake = document.createElement('div');
snowflake.classList.add('snowflake');
const startPositionX = Math.random() * (window.innerWidth / zoomFactor);
const startPositionY = -Math.random() * 50;
snowflake.style.left = `${startPositionX}px`;
snowflake.style.top = `${startPositionY}px`;
const animationDuration = 5 + Math.random() * 5;
const fallDistance = window.innerHeight / zoomFactor;
snowflake.style.setProperty('--fall-distance', `${fallDistance}px`);
snowflake.style.setProperty('--animation-duration', `${animationDuration}s`);
document.body.appendChild(snowflake);
setTimeout(() => {
if (snowflake.parentElement) snowflake.parentElement.removeChild(snowflake);
}, animationDuration * 1000);
}
setInterval(createSnowflake, 50);
});