-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnow.js
More file actions
31 lines (26 loc) · 1.02 KB
/
snow.js
File metadata and controls
31 lines (26 loc) · 1.02 KB
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
// Check if it's December
function isDecember() {
const currentMonth = new Date().getMonth(); // 0-11, where 11 is December
return currentMonth === 11;
}
function createSnowflake() {
const snowflake = document.createElement('div');
snowflake.classList.add('snowflake');
snowflake.style.left = Math.random() * 100 + '%';
snowflake.style.animationDuration = Math.random() * 3 + 2 + 's';
snowflake.style.opacity = Math.random();
snowflake.style.width = snowflake.style.height = Math.random() * 5 + 5 + 'px';
document.querySelector('.snow-container').appendChild(snowflake);
setTimeout(() => {
snowflake.remove();
}, parseFloat(snowflake.style.animationDuration) * 1000);
}
// Only start snow if it's December
if (isDecember()) {
// Create snow container
const snowContainer = document.createElement('div');
snowContainer.classList.add('snow-container');
document.body.prepend(snowContainer);
// Start creating snowflakes
setInterval(createSnowflake, 100);
}