forked from kristelTech/valentines_2025
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
31 lines (25 loc) · 1.32 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
const yesBtn = document.querySelector(".yes-btn");
const noBtn = document.querySelector(".no-btn");
const question = document.querySelector(".question");
const gif = document.querySelector(".gif");
// Change text and gif when the Yes button is clicked
yesBtn.addEventListener("click", () => {
question.innerHTML = "Being with you is my biggest blessing. I love you.";
gif.src = "https://media.giphy.com/media/v1.Y2lkPTc5MGI3NjExbGNhdXh1b252b2F2b2U4cHRlNGkwMDZsajllaGF1cDJyb2p4NXl2YiZlcD12MV9naWZzX3NlYXJjaCZjdD1n/G6N0pDDgDpLjUvNoyQ/giphy.gif";
// Hide the No button
noBtn.style.display = "none";
});
// Make the No button move randomly on hover
noBtn.addEventListener("mouseover", () => {
const wrapper = document.querySelector(".wrapper");
const wrapperRect = wrapper.getBoundingClientRect();
const noBtnRect = noBtn.getBoundingClientRect();
// Calculate max positions to ensure the button stays within the wrapper
const maxX = wrapperRect.width - noBtnRect.width;
const maxY = wrapperRect.height - noBtnRect.height;
// Ensure randomX and randomY are within the wrapper bounds
const randomX = Math.min(Math.floor(Math.random() * maxX), maxX);
const randomY = Math.min(Math.floor(Math.random() * maxY), maxY);
noBtn.style.left = randomX + "px";
noBtn.style.top = randomY + "px";
});