-
Notifications
You must be signed in to change notification settings - Fork 357
Expand file tree
/
Copy pathscript.js
More file actions
72 lines (52 loc) · 2.01 KB
/
script.js
File metadata and controls
72 lines (52 loc) · 2.01 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
// 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";
});