Home  >  Article  >  Web Front-end  >  Build a QR Code Generator Website

Build a QR Code Generator Website

PHPz
PHPzOriginal
2024-08-23 14:31:321171browse

Build a QR Code Generator Website

Introduction

Hello, fellow developers! I'm excited to present my latest project: a QR Code Generator. This project is a great way to dive into JavaScript, focusing on how to dynamically generate QR codes based on user input. Whether you're new to web development or looking to enhance your JavaScript skills, this QR Code Generator project is an excellent opportunity to learn and create something useful.

Project Overview

The QR Code Generator is a web-based application that allows users to generate QR codes from any text input. This project demonstrates how to create a simple and interactive user interface, integrate third-party APIs, and handle user inputs effectively.

Features

  • User-Friendly Interface: Simple and clean design that makes it easy to generate QR codes.
  • Dynamic QR Code Generation: Instantly generates a QR code based on the text input provided by the user.
  • Responsive Design: Ensures a consistent experience across various devices and screen sizes.

Technologies Used

  • HTML: Structures the web page and input elements.
  • CSS: Styles the user interface, ensuring a clean and responsive design.
  • JavaScript: Manages the logic for generating QR codes and handling user interactions.

Project Structure

Here's a quick look at the project structure:

QR-Code-Generator/
├── index.html
├── style.css
└── script.js
  • index.html: Contains the HTML structure for the QR Code Generator.
  • style.css: Includes CSS styles to enhance the appearance and responsiveness of the application.
  • script.js: Manages the QR code generation logic and user interactions.

Installation

To get started with the project, follow these steps:

  1. Clone the repository:

    git clone https://github.com/abhishekgurjar-in/QR-Code-Generator.git
    
  2. Open the project directory:

    cd QR-Code-Generator
    
  3. Run the project:

    • Open the index.html file in a web browser to start using the QR Code Generator.

Usage

  1. Open the website in a web browser.
  2. Enter text in the input field to generate a QR code.
  3. Click the "Generate QR Code" button to see the QR code generated based on the entered text.
  4. Scan the QR code with any QR code reader to view the encoded text.

Code Explanation

HTML

The index.html file provides the basic structure of the QR Code Generator, including the input field and buttons for generating the QR code. Here’s a snippet:

8b05045a5be5764f313ed5b9168a17e6
49099650ebdc5f3125501fa170048923
  93f0f5c25f18dab9d176bd4f6de5d30e
    7c8d9f814bcad6a1d7abe4eda5f773e5
    26faf3d1af674280d03ba217d87e9421
    b2386ffb911b14667cb8f0f91ea547a7QR Code Generator6e916e0f7d1e588d4f442bf645aedb2f
    af75c476cdb7e6c074ca6da9b40841de
    90392ec4442ad9ff612213ec639da4832cacc6d41bbb37262a98f745aa00fbf0
  9c3bca370b5104690d9ef395f2c5f8d1
  6c04bd5ca3fcae76e30b72ad730ca86d
    4883ec0eb33c31828b7c767c806e14c7
      8f9e4409b06fde1ff1d3a80f075ca0ed
        ae3978a23ba5cac816877cfe5cac86ec
          4a249f0d628e2318394fd9b75b4636b1QR Code Generator473f0a7621bec819994bb5020d29372a
          e388a4556c0f65e1904146cc1a846beePaste text to create QR Code94b3e26ee717c64999d7867364b1b4a3
        4d7ab0de9a42de71c682b0860bad1410

        29e7d50c7ce157315e3900dfb0a4e328
          306e6e849fa473d073ec3b364ee18ebd
          01dc540c80e3b84203baf3b36f95a497Generate QR Code65281c5ac262bf6d81768915a4a77ac0
        f5a47148e367a6035fd7a2faa965022e
        28803f9c269550d42ecee4b94492a2e0
          d7182983f39e1ed4f55567871920d692
        4d7ab0de9a42de71c682b0860bad1410
      16b28748ea4df4d9c2150843fecfba68
    16b28748ea4df4d9c2150843fecfba68
    ffd6ba4147bda351239915f463e46e38
      e388a4556c0f65e1904146cc1a846beeMade with ❤️ by Abhishek Gurjar94b3e26ee717c64999d7867364b1b4a3
    16b28748ea4df4d9c2150843fecfba68
  36cc49f0c466276486e50c850b7e4956
73a6ac4ed44ffec12cee46588e518a5e

CSS

The style.css file styles the QR Code Generator, providing a modern and user-friendly layout. Here are some key styles:

@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;500;600;700&display=swap");

:root {
  --primary: #47185c;
  --primary-dark: #14001d;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-family: "Poppins", sans-serif;
}

body {
  background-color: var(--primary);
}

.container {
  display: grid;
  place-items: center;
  height: 80vh;
}

.box {
  padding: 20px;
  width: 400px;
  background-color: white;
}

.upper h1 {
  font-size: 32px;
  font-weight: 400;
  line-height: 32px;
}

form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
}

form input {
  width: 100%;
  height: 40px;
  padding: 10px 15px;
}

form button {
  width: 100%;
  height: 40px;
  padding: 10px 15px;
  background-color: var(--primary);
  border: none;
  color: white;
  opacity: 0.9;
  transition: 0.3s ease-in;
}

.qr_container {
  border: 1px solid var(--primary);
  display: flex;
  justify-content: center;
  height: 0;
  opacity: 0;
  transition: opacity 0.3s ease-in, height 0.1s ease;
}

.qr_container.show {
  padding: 10px;
  height: 150px;
  opacity: 1;
}

.qr_container img {
  height: 100%;
}

.footer {
  color: white;
  margin: 50px;
  text-align: center;
}

JavaScript

The script.js file manages the logic for generating the QR codes and handling user interactions. Here’s a snippet:

const qrFormEl = document.getElementById("qrForm");
const qrImageEl = document.getElementById("qrImage");
const qrContainerEl = document.getElementById("qrContainer");
const qrInputTextEl = document.getElementById("qrInputText");
const generateBtnEl = document.getElementById("generateBtn");

const renderQRCode = (url) => {
  if (!url) return;
  generateBtnEl.innerText = "Generating QR Code...";
  qrImageEl.src = url;

  qrImageEl.addEventListener("load", () => {
    qrContainerEl.classList.add("show");
    generateBtnEl.innerText = "Generate QR Code";
  });
};

qrFormEl.addEventListener("submit", (event) => {
  event.preventDefault();

  const formData = new FormData(qrFormEl);
  const text = formData.get("qrText");
  const qrCodeUrl = `https://api.qrserver.com/v1/create-qr-code/?size=150x150&data=${text}`;

  renderQRCode(qrCodeUrl);
});

qrInputTextEl.addEventListener("keyup", () => {
  if (!qrInputTextEl.value.trim()) {
    qrContainerEl.classList.remove("show");
  }
});

Live Demo

You can check out the live demo of the QR Code Generator here.

Conclusion

Building this QR Code Generator was a fun and educational experience that helped me better understand JavaScript and how to work with APIs to create dynamic web applications. I hope this project inspires you to build something cool with JavaScript too. Happy coding!

Credits

This project was developed as part of my journey to enhance my web development skills, focusing on JavaScript and user interaction.

Author

  • Abhishek Gurjar
    • GitHub Profile

The above is the detailed content of Build a QR Code Generator Website. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn