-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
28 lines (23 loc) · 803 Bytes
/
app.js
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
const container = document.querySelector(".container"),
qrInput = container.querySelector(".fm input"),
generate = container.querySelector(".fm button"),
qrImage = container.querySelector(".qr img");
let preVal;
generate.addEventListener("click", () => {
let qrval = qrInput.value.trim();
if (!qrval || preVal === qrval) {
return;
}
qrImage.src = `https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=${qrval}`;
qrImage.addEventListener("load", () => {
container.classList.add("active");
generate.innerText = "Generating QR..";
});
});
qrInput.addEventListener("keyup", ()=> {
if(!qrInput.value.trim()) {
container.classList.remove("active");
generate.innerText = "Generate QR";
preVal = "";
}
})