비전공자 개발일기

Quote Generator 본문

Javascript

Quote Generator

HiroDaegu 2022. 12. 13. 00:11
728x90
SMALL

<html lang="en">

<head>
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Random Quote Generator</title>
    <!-- Google Font -->
    <link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;600&display=swap" rel="stylesheet" />
    <!-- Stylesheet -->
    <link rel="stylesheet" href="style.css" />
    <!-- Script -->
    <script defer src="main.js"></script>
</head>

<body>
    <div class="wrapper">
        <div class="container">
            <p id="quote">
                Lorem ipsum dolor, sit amet consectetur adipisicing elit. Voluptas,
                magni.
            </p>
            <h3 id="author">Lorem, ipsum.</h3>
            <button id="btn">Get Quote</button>
        </div>
    </div>

</body>

</html>
* {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
    font-family: "Poppins", sans-serif;
  }
  body {
    background-color: #f43543;
  }
  .wrapper {
    width: 400px;
    position: absolute;
    transform: translate(-50%, -50%);
    top: 50%;
    left: 50%;
  }
  .container {
    width: 100%;
    background-color: #f43543;
    padding: 50px 40px;
    box-shadow: 0 20px 65px rgba(87, 11, 16, 0.5);
    position: relative;
    border-radius: 8px;
    text-align: center;
  }
  .container:after {
    content: "";
    position: absolute;
    width: 80%;
    height: 120%;
    background-color: #ffffff;
    z-index: -1;
    top: -10%;
    left: 10%;
  }
  .container p {
    color: #fdd8d8;
    line-height: 2;
    font-size: 18px;
  }
  .container h3 {
    color: #ffffff;
    margin: 20px 0 60px 0;
    font-weight: 600;
    text-transform: capitalize;
  }
  .container button {
    background-color: #ffffff;
    border: none;
    padding: 15px 45px;
    border-radius: 5px;
    font-size: 18px;
    font-weight: 600;
    color: #f43543;
    cursor: pointer;
  }
let quote = document.getElementById("quote");
let author = document.getElementById("author");
let btn = document.getElementById("btn");

const url = "https://api.quotable.io/random";

let getQuote = () => {
  fetch(url)
    .then((data) => data.json())
    .then((item) => {
      quote.innerText = item.content;
      author.innerText = item.author;
    });
};

window.addEventListener("load", getQuote);
btn.addEventListener("click", getQuote);
728x90
LIST

'Javascript' 카테고리의 다른 글

Recipe App  (0) 2022.12.15
Interest calcalator  (0) 2022.12.14
Get User Location  (0) 2022.12.11
Calculator basic operator  (0) 2022.12.09
Create Email Validation  (0) 2022.12.08