File tree Expand file tree Collapse file tree 3 files changed +89
-11
lines changed Expand file tree Collapse file tree 3 files changed +89
-11
lines changed Original file line number Diff line number Diff line change 10
10
< title > Promo Code</ title >
11
11
</ head >
12
12
< body >
13
- < div class ="present " id ="present ">
13
+ <!-- Make it Accessible on Focus -->
14
+ < div class ="present " id ="present " tabindex ="0 ">
14
15
< div class ="lid ">
15
16
< span > </ span >
16
17
</ div >
17
18
< div class ="promo ">
18
19
< 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 >
20
22
</ div >
21
23
< div class ="box ">
22
24
< span > </ span >
23
25
< span > </ span >
24
26
</ div >
25
27
</ 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 >
27
29
< script src ="script.js "> </ script >
28
30
</ body >
29
31
</ html >
Original file line number Diff line number Diff line change 1
1
const present = document . getElementById ( "present" ) ;
2
+ const copyBtn = document . getElementById ( "copy-btn" ) ;
3
+
4
+ // Customize Confetti Animation
2
5
const options = {
6
+ particleCount : 200 ,
7
+ spread : 90 ,
8
+ gravity : 0.8 ,
9
+ shapes : [ "star" ] ,
3
10
colors : [
4
11
"#34D963" ,
5
12
"#068C2C" ,
@@ -11,9 +18,38 @@ const options = {
11
18
] ,
12
19
} ;
13
20
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
+ }
16
35
} ) ;
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
+ } ) ;
19
55
} ) ;
Original file line number Diff line number Diff line change 5
5
}
6
6
7
7
body {
8
- background : # 232526 ;
9
- background : linear-gradient (to top, # 414345, # 232526 );
8
+ background : # 232526 ;
9
+ background : linear-gradient (to top, # 414345, # 232526 );
10
10
font-family : "Itim" , cursive;
11
11
min-height : 100vh ;
12
12
margin : 0 ;
@@ -87,17 +87,57 @@ body {
87
87
margin : 0 ;
88
88
}
89
89
90
+ /* Add a "Copy to Clipboard" Button */
90
91
.promo h2 {
91
92
font-size : 40px ;
92
93
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;
93
127
}
94
128
95
- .present : hover .lid {
129
+ .present:hover .promo,
130
+ .present:focus-within .promo {
131
+ top: -80px;
132
+ } */
133
+
134
+ .present .open .lid {
96
135
top : -100px ;
97
136
transform : rotateZ (10deg );
98
137
left : 10px ;
99
138
}
100
139
101
- .present : hover .promo {
140
+ /* Toggle Animation on Click */
141
+ .present .open .promo {
102
142
top : -80px ;
103
143
}
You can’t perform that action at this time.
0 commit comments