Skip to content

Commit 80ae9a7

Browse files
committed
feat: day 88
1 parent f56897f commit 80ae9a7

File tree

3 files changed

+89
-11
lines changed

3 files changed

+89
-11
lines changed

088-promo code/index.html

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,22 @@
1010
<title>Promo Code</title>
1111
</head>
1212
<body>
13-
<div class="present" id="present">
13+
<!-- Make it Accessible on Focus -->
14+
<div class="present" id="present" tabindex="0">
1415
<div class="lid">
1516
<span></span>
1617
</div>
1718
<div class="promo">
1819
<p>20% off promo</p>
19-
<h2>ILOVEYOU</h2>
20+
<!-- Add a "Copy to Clipboard" Button -->
21+
<h2>ILOVEYOU <button id="copy-btn" type="button">Copy</button></h2>
2022
</div>
2123
<div class="box">
2224
<span></span>
2325
<span></span>
2426
</div>
2527
</div>
26-
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.4.0/dist/confetti.browser.min.js"></script>
28+
<script src="https://cdn.jsdelivr.net/npm/canvas-confetti@1.9.3/dist/confetti.browser.min.js"></script>
2729
<script src="script.js"></script>
2830
</body>
2931
</html>

088-promo code/script.js

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
const present = document.getElementById("present");
2+
const copyBtn = document.getElementById("copy-btn");
3+
4+
// Customize Confetti Animation
25
const options = {
6+
particleCount: 200,
7+
spread: 90,
8+
gravity: 0.8,
9+
shapes: ["star"],
310
colors: [
411
"#34D963",
512
"#068C2C",
@@ -11,9 +18,38 @@ const options = {
1118
],
1219
};
1320

14-
present.addEventListener("mouseenter", () => {
15-
confetti(options);
21+
// present.addEventListener("mouseenter", () => {
22+
// confetti(options);
23+
// });
24+
// present.addEventListener("touchstart", () => {
25+
// confetti(options);
26+
// });
27+
28+
// Toggle Animation on Click
29+
present.addEventListener("click", () => {
30+
const isOpening = !present.classList.contains("open");
31+
present.classList.toggle("open");
32+
if (isOpening) {
33+
confetti(options);
34+
}
1635
});
17-
present.addEventListener("touchstart", () => {
18-
confetti(options);
36+
37+
present.addEventListener("keydown", (e) => {
38+
if (e.key === "Enter" || e.key === " ") {
39+
e.preventDefault();
40+
present.click();
41+
}
42+
});
43+
44+
// Add a "Copy to Clipboard" Button
45+
copyBtn.addEventListener("click", (e) => {
46+
e.stopPropagation();
47+
const promoCode = copyBtn.parentElement.firstChild.textContent.trim();
48+
navigator.clipboard.writeText(promoCode).then(() => {
49+
const originalText = copyBtn.textContent;
50+
copyBtn.textContent = "Copied!";
51+
setTimeout(() => {
52+
copyBtn.textContent = originalText;
53+
}, 1500);
54+
});
1955
});

088-promo code/style.css

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
}
66

77
body {
8-
background: #232526;
9-
background: linear-gradient(to top, #414345, #232526);
8+
background: #232526;
9+
background: linear-gradient(to top, #414345, #232526);
1010
font-family: "Itim", cursive;
1111
min-height: 100vh;
1212
margin: 0;
@@ -87,17 +87,57 @@ body {
8787
margin: 0;
8888
}
8989

90+
/* Add a "Copy to Clipboard" Button */
9091
.promo h2 {
9192
font-size: 40px;
9293
margin: 0;
94+
display: flex;
95+
align-items: center;
96+
justify-content: center;
97+
gap: 10px;
98+
}
99+
100+
.promo button {
101+
background: #50514f;
102+
color: #fff;
103+
font-family: inherit;
104+
font-size: 1rem;
105+
font-weight: bold;
106+
border: none;
107+
border-radius: 10px;
108+
padding: 6px 18px;
109+
margin: 0;
110+
min-width: 100px;
111+
cursor: pointer;
112+
transition: background 0.2s;
113+
}
114+
115+
.promo button:hover,
116+
.promo button:focus {
117+
background: #2c4251;
118+
outline: none;
119+
}
120+
121+
/* Make it Accessible on Focus */
122+
/* .present:hover .lid,
123+
.present:focus-within .lid {
124+
top: -100px;
125+
transform: rotateZ(10deg);
126+
left: 10px;
93127
}
94128
95-
.present:hover .lid {
129+
.present:hover .promo,
130+
.present:focus-within .promo {
131+
top: -80px;
132+
} */
133+
134+
.present.open .lid {
96135
top: -100px;
97136
transform: rotateZ(10deg);
98137
left: 10px;
99138
}
100139

101-
.present:hover .promo {
140+
/* Toggle Animation on Click */
141+
.present.open .promo {
102142
top: -80px;
103143
}

0 commit comments

Comments
 (0)