-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
55 lines (38 loc) · 1.66 KB
/
app.js
File metadata and controls
55 lines (38 loc) · 1.66 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
const yesButton = document.querySelector('.yes-btn');
const noButton = document.querySelector('.no-btn');
const thankYouMessage = document.querySelector('.thank-you');
const body = document.body;
yesButton.addEventListener('click', function(event) {
const clickX = event.clientX;
const clickY = event.clientY;
for (let i = 0; i < 10; i++) {
createHeart(clickX, clickY);
}
body.style.background = "linear-gradient(135deg,rgba(16, 68, 65, 0.25) 0%, #fad0c4 100%)";
thankYouMessage.style.display = "flex";
// Hide buttons
yesButton.style.display = "none";
noButton.style.display = "none";
});
noButton.addEventListener('mouseover', function() {
// Move button to random position
const randomX = Math.random() * (window.innerWidth - 100);
const randomY = Math.random() * (window.innerHeight - 50);
noButton.style.position = "absolute";
noButton.style.left = randomX + "px";
noButton.style.top = randomY + "px";
const messages = ["Are you sure?", "Please?", "No 😒", "Try again!", "Click Yes!"];
noButton.textContent = messages[Math.floor(Math.random() * messages.length)];
});
// Function to create a heart at position
function createHeart(x, y) {
const heart = document.createElement('div');
heart.className = 'heart';
heart.textContent = '❤️ ❤️ ❤️';
const offsetX = (Math.random() - 0.5) * 400;
const offsetY = (Math.random() - 0.5) * 400;
heart.style.left = (x + offsetX) + 'px';
heart.style.top = (y + offsetY) + 'px';
document.body.appendChild(heart);
setTimeout(() => heart.remove(), 10000);
}