-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
91 lines (65 loc) · 2.56 KB
/
script.js
File metadata and controls
91 lines (65 loc) · 2.56 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
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
// Elements
const envelope = document.getElementById("envelope-container");
const letter = document.getElementById("letter-container");
const noBtn = document.querySelector(".no-btn");
const yesBtn = 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");
// Click Envelope
envelope.addEventListener("click", () => {
envelope.style.display = "none";
letter.style.display = "flex";
setTimeout( () => {
document.querySelector(".letter-window").classList.add("open");
},50);
});
// Logic to move the NO btn
noBtn.addEventListener("mouseover", () => {
const min = 200;
const max = 200;
const distance = Math.random() * (max - min) + min;
const angle = Math.random() * Math.PI * 2;
const moveX = Math.cos(angle) * distance;
const moveY = Math.sin(angle) * distance;
noBtn.style.transition = "transform 0.3s ease";
noBtn.style.transform = `translate(${moveX}px, ${moveY}px)`;
});
// Logic to make YES btn to grow
// let yesScale = 1;
// yesBtn.style.position = "relative"
// yesBtn.style.transformOrigin = "center center";
// yesBtn.style.transition = "transform 0.3s ease";
// noBtn.addEventListener("click", () => {
// yesScale += 2;
// if (yesBtn.style.position !== "fixed") {
// yesBtn.style.position = "fixed";
// yesBtn.style.top = "50%";
// yesBtn.style.left = "50%";
// yesBtn.style.transform = `translate(-50%, -50%) scale(${yesScale})`;
// }else{
// yesBtn.style.transform = `translate(-50%, -50%) scale(${yesScale})`;
// }
// });
// YES is clicked
yesBtn.addEventListener("click", () => {
title.textContent = "Yippeeee!";
catImg.src = "cat_dance.gif";
document.querySelector(".letter-window").classList.add("final");
buttons.style.display = "none";
finalText.style.display = "block";
});
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);
}
});