-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfalling-stars.js
More file actions
39 lines (33 loc) · 1.07 KB
/
falling-stars.js
File metadata and controls
39 lines (33 loc) · 1.07 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
32
33
34
35
36
37
38
39
document.addEventListener('DOMContentLoaded', () => {
const starsContainer = document.querySelector('.falling-stars-container');
function createFallingStar() {
const star = document.createElement('div');
star.classList.add('falling-star');
// Random horizontal start position
const startX = Math.random() * window.innerWidth;
star.style.left = `${startX}px`;
// Random starting opacity and size
const opacity = 0.3 + Math.random() * 0.4;
const size = 1 + Math.random() * 2;
star.style.width = `${size}px`;
star.style.height = `${size * 10}px`;
star.style.opacity = opacity;
starsContainer.appendChild(star);
// Animate falling
gsap.to(star, {
y: window.innerHeight + 100,
x: startX + (Math.random() - 0.5) * 200,
rotation: -45,
duration: 3 + Math.random() * 3,
ease: 'linear',
onComplete: () => {
star.remove();
createFallingStar();
}
});
}
// Create initial set of falling stars
for (let i = 0; i < 20; i++) {
createFallingStar();
}
});