-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (40 loc) · 1.48 KB
/
Copy pathscript.js
File metadata and controls
43 lines (40 loc) · 1.48 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
40
41
42
43
// Heart animation
setInterval(() => {
const heart = document.createElement('div');
heart.classList.add('heart');
heart.style.left = Math.random() * 100 + 'vw';
heart.style.top = '100vh';
heart.style.position = 'absolute'; // Ensures heart appears on screen
heart.style.animationDuration = (Math.random() * 3 + 2) + 's';
document.body.appendChild(heart);
setTimeout(() => heart.remove(), 5000);
}, 300);
// Confetti animation
function throwConfetti() {
for (let i = 0; i < 100; i++) {
const confetti = document.createElement('div');
confetti.classList.add('confetti');
confetti.style.left = Math.random() * 100 + 'vw';
confetti.style.top = '-10px';
confetti.style.position = 'absolute'; // Ensures confetti appears on screen
confetti.style.width = '8px';
confetti.style.height = '8px';
confetti.style.borderRadius = '50%';
confetti.style.background = `hsl(${Math.random() * 360}, 100%, 50%)`;
confetti.style.animation = 'fall 2s linear';
document.body.appendChild(confetti);
setTimeout(() => confetti.remove(), 2000);
}
}
document.getElementById('yesBtn').addEventListener('click', () => {
throwConfetti();
alert('Yay!! I can’t wait 💖🥰');
});
// No button runs away
const noBtn = document.getElementById('noBtn');
noBtn.addEventListener('mouseover', () => {
const x = Math.random() * 200 - 100;
const y = Math.random() * 200 - 100;
noBtn.style.position = 'relative';
noBtn.style.transform = `translate(${x}px, ${y}px)`;
});