Build a QR Code Generator Web App in HTML5 CSS3 and Vanilla Javascript Full Project For Beginners

 

 

index.html

 

 

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- css -->
    <link rel="stylesheet" href="style.css">
</head>

<body>

    <h1>QR Code Generator</h1>
    <input type="text" id="input" placeholder="Enter Value" />
    <button type="submit" id="qr-btn">Generate QR</button>
    <span id="loading"></span>
    <img src="" alt="" id="qr-img" />

    <!-- javascript -->
    <script src="script.js"></script>
</body>

</html>

 

 

style.css

 

 

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    outline: none;
    border: none;
    font-family: Arial;
    letter-spacing: 1px;
}

body {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: url(img.jpg);
    background-size: cover;
    background-repeat: no-repeat;
    color: #fff;
    position: relative;
}

body::after {
    position: absolute;
    content: '';
    z-index: -1;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    background-color: #00012ef0;
}

h1 {
    font-size: 5em;
}

input {
    width: 400px;
    height: 50px;
    border-bottom: 2px solid #fff;
    background-color: #ffffff26;
    padding: 15px;
    color: #fff;
    font-size: 1.5em;
    margin: 30px;
}

button {
    width: 400px;
    height: 50px;
    font-size: 1.5em;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 30px;
    transition: 0.4s;
}

button:active {
    background-color: #ffffff26;
}

#loading {
    display: none;
    width: 40px;
    height: 40px;
    margin-bottom: 30px;
    border-radius: 50%;
    border: 5px solid #ffffff26;
    border-top: 5px solid #fff;
    animation: loading 1s linear infinite;
}

@keyframes loading {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

 

 

script.js

 

 

var qr_btn = document.querySelector("#qr-btn")
var qr_img = document.querySelector("#qr-img")
var loading = document.querySelector("#loading")

qr_btn.addEventListener("click", () => {
    // loading
    loading.style.display = "block"
    qr_img.onload = function() {
        loading.style.display = "none"
    }

    // generate image
    var input = document.querySelector("#input").value
    var url = `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${input}`
    qr_img.src = url
})

 

 

 

DOWNLOAD SOURCE CODE

 

 

Leave a Reply