-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathscript.js
108 lines (80 loc) · 3.33 KB
/
script.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
function onWindowLoad() {
alert("WARNING!!! PLEASE ANSWER THE FOLLOWING QUESTION CAREFULLY!");
}
window.onload = onWindowLoad;
function playMusic() {
const noImage = document.getElementById('noImage');
if (noImage.style.display === 'none') {
const musicAudio = document.getElementById('musicAudio');
musicAudio.play();
}
}
document.addEventListener('mousemove', playMusic);
function moveNoButton() {
const noButton = document.getElementById('noButton');
const yesButton = document.getElementById('yesButton');
const minDistance = 100;
let randomX, randomY;
do {
randomX = Math.random() < 0.5 ? Math.floor(Math.random() * 800) + 1 : -Math.floor(Math.random() * 900) + 1;
randomY = Math.random() < 0.5 ? Math.floor(Math.random() * 300) + 1 : -Math.floor(Math.random() * 800) + 1;
} while (isTooClose(randomX, randomY, yesButton, minDistance));
noButton.style.left = `${randomX}px`;
noButton.style.top = `${randomY}px`;
const valentineImage = document.getElementById('valentineImage');
valentineImage.style.display = 'none';
const noImage = document.getElementById('noImage');
noImage.style.display = 'inline-block';
const musicAudio = document.getElementById('musicAudio');
musicAudio.pause();
const noAudio = document.getElementById('noAudio');
noAudio.play();
}
function isTooClose(x, y, element, minDistance) {
const rectNo = element.getBoundingClientRect();
const rectNew = { x, y, width: 100, height: 20 };
return (
rectNew.x < rectNo.x + rectNo.width + minDistance &&
rectNew.x + rectNew.width > rectNo.x - minDistance &&
rectNew.y < rectNo.y + rectNo.height + minDistance &&
rectNew.y + rectNew.height > rectNo.y - minDistance
);
}
const jsConfetti = new JSConfetti();
function yesButton() {
const yesTitle = document.getElementById('yesTitle');
yesTitle.style.display = 'block';
const yesCaption = document.getElementById('yesCaption');
yesCaption.style.display = 'block';
const questionTitle = document.getElementById('questionTitle');
questionTitle.style.display = 'none';
const yesImage = document.getElementById('yesImage');
yesImage.style.display = 'inline-block';
const valentineImage = document.getElementById('valentineImage');
valentineImage.style.display = 'none';
const noImage = document.getElementById('noImage');
noImage.style.display = 'none';
const yesButton = document.getElementById('yesButton');
yesButton.style.display = 'none';
const noButton = document.getElementById('noButton');
noButton.style.display = 'none';
const musicAudio = document.getElementById('musicAudio');
musicAudio.play();
const yesAudio = document.getElementById('yesAudio');
yesAudio.play();
jsConfetti.addConfetti({
emojis: ['🌈', '⚡️', '💥', '✨', '💫', '🌸', '🎉', '🌟', '🍭', '🌼', '💖', '🦄'],
emojiSize: 100,
confettiNumber: 100,
});
}
function confetti() {
if (yesImage.style.display !== 'none') {
jsConfetti.addConfetti({
emojis: ['🌈', '⚡️', '💥', '✨', '💫', '🌸', '🎉', '🌟', '🍭', '🌼', '💖', '🦄'],
emojiSize: 100,
confettiNumber: 100,
});
}
}
document.addEventListener('click', confetti);