-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
247 lines (192 loc) · 5.33 KB
/
index.html
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<html>
<head>
<title>QR-CODE Generator</title>
<!-- CSS Styling begins from here -->
<style>
* {
margin: 0;
box-sizing: border-box;
font-family: Arial, Helvetica, sans-serif;
}
body {
display: flex;
min-height: 100vh;
align-items: center;
background-image: url('qr_bg.jpg');
justify-content: center;
}
h1{
background-color: #adadad;
height: 50px;
text-align: center;
padding-top: 10px;
}
.qr_box {
position: relative;
height: 300px;
width: 500px;
background: #cecccc;
border-radius: 10px;
border: 2px solid rgb(0, 0, 0);
padding: 20px 25px 0;
box-shadow: 0 0 50px rgba(246, 248, 246, 0.5),
0 0 50px rgba(231, 238, 231, 0.4), 0 0 50px rgba(238, 239, 238, 0.3),
0 0 50px rgba(235, 238, 235, 0.2);
}
.qr_box.active {
height: 600px;
}
header h1 {
font-size: 21px;
padding: 15px;
}
header p {
margin-top: 5px;
color: #3f3f3f;
text-align: center;
font-size: 16px;
}
.qr_box .form {
margin: 20px 0 25px;
}
.form :where(input, button) {
width: 100%;
height: 55px;
border-radius: 50px;
}
.form input {
font-size: 18px;
padding: 0 17px;
border: 1px solid #000000;
}
.form input::placeholder {
color: #827f7f;
}
.form button {
font-weight: bold;
color: #fff;
cursor: pointer;
margin-top: 20px;
font-size: 18px;
background: #42a22b;
text-align: center;
cursor:pointer;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-property:box-shadow,transform ;
transition-property:box-shadow,transform ;
}
.form button:hover, .form button:focus, .form button:active{
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
.download button {
display: none; /* The download button is initially hidden */
font-weight: bold;
color: #fff;
margin-top: 20px;
font-size: 18px;
background: #2d86ce;
text-align: center;
cursor:pointer;
-webkit-transition-duration: 0.3s;
transition-duration: 0.3s;
-webkit-transition-property:box-shadow,transform ;
transition-property:box-shadow,transform ;
}
.qr_box.active .download button {
display: block;
}
.download button:hover, .download button:focus, .download button:active{
-webkit-transform: scale(1.1);
transform: scale(1.1);
}
.qr-code {
opacity: 0;
display: flex;
padding: 33px;
border-radius: 20px;
align-items: center;
justify-content: center;
border: 2px solid #65afdb;
}
.qr_box.active .qr-code {
opacity: 1;
pointer-events: auto;
}
.qr-code img {
width: 170px;
}
.foot {
position: fixed;
bottom: 0;
width: 100%;
background-color:rgb(28, 22, 64);
padding: 7px;
color: rgb(206, 205, 205);
text-align: center;
}
</style>
<!-- CSS Styling ends here -->
</head>
<!-- HTML Body begins from here -->
<body>
<div class="qr_box">
<header>
<h1>QR Code Generator</h1>
<p>Paste URL or Enter TEXT to create QR-Code</p>
</header>
<div class="form">
<input type="text" placeholder="Enter URL or TEXT">
<button>Generate QR Code</button>
<div class="download">
<button id="download">Download QR</button>
</div>
</div>
<div class="qr-code">
<img src="" alt="qr-code">
</div>
</div>
<div class="foot">
<footer>© QR Code Generator. All rights reserved.</footer>
</div>
<!-- HTML Body ends here -->
<!-- JavaScript begins from here -->
<script>
const qr_box = document.querySelector(".qr_box"),
qrInput = qr_box.querySelector(".form input"),
generateBtn = qr_box.querySelector(".form button"),
qrImg = qr_box.querySelector(".qr-code img");
let preValue;
const downloadBtn=document.querySelector(".download");
generateBtn.addEventListener("click", () => {
let qrValue = qrInput.value.trim();
if(!qrValue || preValue === qrValue) return;
preValue = qrValue;
generateBtn.innerText = "Generating QR Code...";
qrImg.src = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${qrValue}`;
qrImg.addEventListener("load", () => {
qr_box.classList.add("active");
generateBtn.innerText = "Generate QR Code";
document.querySelector(".download button").style.display = "block";
});
});
qrInput.addEventListener("keyup", () => { /*keyup is an event in JavaScript that is triggered when a keyboard key is released.*/
if(!qrInput.value.trim()) {
qr_box.classList.remove("active");
preValue = "";
}
document.querySelector(".download button").style.display = "none";
});
downloadBtn.addEventListener("click", async ()=>{
const response=await fetch(qrImg.src);
const blob=await response.blob();
const downloadLink=document.createElement("a");
downloadLink.href=URL.createObjectURL(blob);
downloadLink.download="qrcode.jpg";
downloadLink.click();
});
</script>
<!-- JavaScript ends here -->
</body>
</html>