-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
60 lines (48 loc) · 1.92 KB
/
script.js
File metadata and controls
60 lines (48 loc) · 1.92 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
// Elements
const envelope = document.getElementById("envelope-container");
const letter = document.getElementById("letter-container");
const heartBtn = document.querySelector(".no-btn");
const nextBtn = document.querySelector(".btn[alt='Yes']");
const title = document.getElementById("letter-title");
const catImg = document.getElementById("letter-cat");
const buttons = document.getElementById("letter-buttons");
const finalText = document.getElementById("final-text");
// Open envelope
envelope.addEventListener("click", () => {
envelope.style.display = "none";
letter.style.display = "flex";
setTimeout(() => {
document.querySelector(".letter-window").classList.add("open");
}, 50);
});
// heart button runs away
heartBtn.addEventListener("mouseover", () => {
const distance = 200;
const angle = Math.random() * Math.PI * 2;
const moveX = Math.cos(angle) * distance;
const moveY = Math.sin(angle) * distance;
heartBtn.style.transition = "transform 0.3s ease";
heartBtn.style.transform = `translate(${moveX}px, ${moveY}px)`;
});
// next clicked → party mode
nextBtn.addEventListener("click", () => {
title.textContent = "LET’S PARTY!! 🎉";
catImg.src = "cat_dance.gif";
document.querySelector(".letter-window").classList.add("final");
buttons.style.display = "none";
finalText.style.display = "block";
});
// Star confetti
const colors = ["#75dbd3", "#b678ab", "#f58cbd", "#ffe066", "#93cf91"];
document.addEventListener("click", function (e) {
for (let i = 0; i < 12; i++) {
const star = document.createElement("div");
star.innerHTML = "✦";
star.className = "star";
star.style.color = colors[Math.floor(Math.random() * colors.length)];
star.style.left = e.clientX + (Math.random() * 40 - 20) + "px";
star.style.top = e.clientY + (Math.random() * 40 - 20) + "px";
document.body.appendChild(star);
setTimeout(() => star.remove(), 900);
}
});