-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
45 lines (37 loc) · 1.66 KB
/
main.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
const container = document.getElementById("container");
const imageOne = document.querySelector(".image-1");
const imageTwo = document.querySelector(".image-2");
const btnYes = document.querySelector(".btn-yes");
const btnNo = document.querySelector(".btn-no");
function getRandomNumber(min, max) {
// Calculate the random number between min and max (inclusive)
const randomNumber = Math.floor(Math.random() * (max - min + 1)) + min;
return randomNumber;
}
btnNo.addEventListener("mouseover", (event) => {
const containerHeight = container.getBoundingClientRect().height;
const containerWidth = container.getBoundingClientRect().width;
const btnHeight = btnNo.getBoundingClientRect().height;
const btnWidth = btnNo.getBoundingClientRect().width;
const btnTop = btnNo.getBoundingClientRect().top;
const btnLeft = btnNo.getBoundingClientRect().left;
let newTop = btnTop;
let newLeft = btnLeft;
while (Math.abs(newTop - btnTop) < containerHeight / 3) {
newTop = getRandomNumber(0, containerHeight - btnHeight);
}
while (Math.abs(newLeft - btnLeft) < containerWidth / 3) {
newLeft = getRandomNumber(0, containerWidth - btnWidth);
}
btnNo.style.top = Math.floor(newTop) + "px";
btnNo.style.left = Math.floor(newLeft) + "px";
});
btnYes.addEventListener("click", (e) => {
btnNo.classList.add("hide");
imageOne.classList.add("hide");
imageTwo.classList.remove("hide");
// Add a delay before redirecting to the birthday page
setTimeout(() => {
window.location.href = 'birthday.html'; // Change this to your actual birthday page file name
}, 2000); // Delay of 3000 milliseconds (3 seconds)
});