forked from SahilGogna/v-day
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyes-script.js
More file actions
63 lines (55 loc) · 1.54 KB
/
yes-script.js
File metadata and controls
63 lines (55 loc) · 1.54 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
let musicPlaying = false
window.addEventListener('load', () => {
launchConfetti()
// Autoplay music (works since user clicked Yes to get here)
const music = document.getElementById('bg-music')
music.volume = 0.3
music.play().catch(() => {})
musicPlaying = true
document.getElementById('music-toggle').textContent = '🔊'
})
function launchConfetti() {
const colors = ['#ff69b4', '#ff1493', '#ff85a2', '#ffb3c1', '#ff0000', '#ff6347', '#fff', '#ffdf00']
const duration = 6000
const end = Date.now() + duration
// Initial big burst
confetti({
particleCount: 150,
spread: 100,
origin: { x: 0.5, y: 0.3 },
colors
})
// Continuous side cannons
const interval = setInterval(() => {
if (Date.now() > end) {
clearInterval(interval)
return
}
confetti({
particleCount: 40,
angle: 60,
spread: 55,
origin: { x: 0, y: 0.6 },
colors
})
confetti({
particleCount: 40,
angle: 120,
spread: 55,
origin: { x: 1, y: 0.6 },
colors
})
}, 300)
}
function toggleMusic() {
const music = document.getElementById('bg-music')
if (musicPlaying) {
music.pause()
musicPlaying = false
document.getElementById('music-toggle').textContent = '🔇'
} else {
music.play()
musicPlaying = true
document.getElementById('music-toggle').textContent = '🔊'
}
}