-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfireworks.js
116 lines (89 loc) · 3.77 KB
/
fireworks.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
document.addEventListener('DOMContentLoaded', function() {
const button = document.querySelector('.click-me');
const fireworksContainer = document.getElementById('fireworks-container');
console.log('Button:', button);
console.log('Fireworks container:', fireworksContainer);
if (!button || !fireworksContainer) {
console.error('Button or fireworks container not found!');
return;
}
button.addEventListener('click', function() {
console.log('Button clicked');
createRocket();
button.classList.add('slam');
setTimeout(() => {
button.classList.remove('slam');
}, 500);
});
function createRocket() {
console.log('Creating rocket');
const rocket = document.createElement('div');
rocket.className = 'rocket';
const c = Math.random() * window.innerWidth;
rocket.style.left = `${c}px`;
rocket.style.bottom = '0px';
rocket.style.animationDuration = '1.5s';
fireworksContainer.appendChild(rocket);
rocket.addEventListener('animationend', function() {
rocket.remove();
createCartoonExplosion(c)
createFirework(c);
});
rocket.classList.add('launch');
function createCartoonExplosion(c) {
console.log('Creating cartoon explosion at:', c);
const explosion = document.createElement('div');
explosion.className = 'explosion';
const size = 50;
explosion.style.width = `${size}px`;
explosion.style.height = `${size}px`;
explosion.style.left = `${c - size / 2}px`;
explosion.style.top = '50%';
fireworksContainer.appendChild(explosion);
console.log('Cartoon explosion added to container');
explosion.addEventListener('animationend', function() {
explosion.remove();
console.log('Cartoon explosion removed');
});
}
};
function createFirework(c) {
console.log('Creating firework');
const firework = document.createElement('div');
firework.className = 'firework';
const size = Math.random() * 600 + 250;
const halfSize = size / 2;
const x = Math.random() * (window.innerWidth - size) + halfSize;
const y = Math.random() * (window.innerHeight - size) + halfSize;
firework.style.width = `${size}px`;
firework.style.height = `${size}px`;
firework.style.left = `${c - halfSize}px`;
firework.style.top = `${y}px`;
const colors = [
`rgba(233, 86, 112, 0.8)`, // Rose
`rgba(255, 140, 0, 0.8)`, // Dark Orange
`rgba(193, 151, 210, 0.8)`, // Purp
`rgba(255, 215, 0, 0.8)`, // Gold
`rgba(214, 123, 168, 0.8)`, // Indigo
];
const color = colors[Math.floor(Math.random() * colors.length)];
for (let i = 0; i < 5; i++) {
const sparkle = document.createElement('div');
sparkle.className = 'sparkle';
sparkle.style.width = `${Math.random() * 250 + 80}px`;
sparkle.style.height = sparkle.style.width;
sparkle.style.backgroundColor = color;
sparkle.style.left = `${Math.random() * 90}%`;
sparkle.style.top = `${Math.random() * 90}%`;
sparkle.style.animationDuration = `${Math.random() * 25 + 15}s`;
sparkle.style.animationTimingFunction = 'ease-out';
firework.appendChild(sparkle);
}
fireworksContainer.appendChild(firework);
console.log('Firework added to container');
firework.addEventListener('animationend', function() {
firework.remove();
console.log('Firework removed');
});
}
});