[30일 챌린지 Day-3] input값 적용하기

2022. 7. 25. 12:27·개발/html, css, js
728x90
반응형

1. 기본값

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Scoped CSS Variables and JS</title>
</head>
<body>
  <h2>Update CSS Variables with <span class='hl'>JS</span></h2>

  <div class="controls">
    <label for="spacing">Spacing:</label>
    <input id="spacing" type="range" name="spacing" min="10" max="200" value="10" data-sizing="px">

    <label for="blur">Blur:</label>
    <input id="blur" type="range" name="blur" min="0" max="25" value="10" data-sizing="px">

    <label for="base">Base Color</label>
    <input id="base" type="color" name="base" value="#ffc600">
  </div>

  <img src="https://source.unsplash.com/7bwQXzbF6KE/800x500">

  <style>

    /*
      misc styles, nothing to do with CSS variables
    */

    body {
      text-align: center;
      background: #193549;
      color: white;
      font-family: 'helvetica neue', sans-serif;
      font-weight: 100;
      font-size: 50px;
    }

    .controls {
      margin-bottom: 50px;
    }

    input {
      width: 100px;
    }
  </style>

  <script>
  </script>

</body>
</html>

2. 결과

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Scoped CSS Variables and JS</title>
  </head>
  <body>
    <h2>Update CSS Variables with <span class="hl">JS</span></h2>

    <div class="controls">
      <label for="spacing">Spacing:</label>
      <input
        id="spacing"
        type="range"
        name="spacing"
        min="10"
        max="200"
        value="10"
        data-sizing="px"
      />

      <label for="blur">Blur:</label>
      <input
        id="blur"
        type="range"
        name="blur"
        min="0"
        max="25"
        value="10"
        data-sizing="px"
      />

      <label for="base">Base Color</label>
      <input id="base" type="color" name="base" value="#ffc600" />
    </div>
    <div class="imgCover">
      <img src="https://source.unsplash.com/7bwQXzbF6KE/800x500" />
    </div>
    <style>
      /*
      misc styles, nothing to do with CSS variables
    */

      body {
        text-align: center;
        background: #193549;
        color: white;
        font-family: "helvetica neue", sans-serif;
        font-weight: 100;
        font-size: 50px;
      }

      .controls {
        margin-bottom: 50px;
      }

      input {
        width: 100px;
      }
      /* 여기서부터 추가 */
      .imgCover {
        width: 800px;
        height: 500px;
        margin: auto;
        background-color: white;
        filter: blur();
      }
    </style>

    <script>
      const imgCover = document.querySelector(".imgCover");
      const blur = document.getElementById("blur");
      const spacing = document.getElementById("spacing");
      const base = document.getElementById("base");
      const hl = document.querySelector(".hl");

      //spacing 설정
      imgCover.style.padding = `${spacing.value}px`;
      spacing.oninput = () => {
        imgCover.style.padding = `${spacing.value}px`;
      };

      //blur설정
      imgCover.style.filter = `blur(${blur.value}px)`;
      blur.oninput = () => {
        imgCover.style.filter = `blur(${blur.value}px)`;
      };

      //background 설정
      imgCover.style.backgroundColor = `${base.value}`;
      hl.style.color = `${base.value}`;
      base.onchange = () => {
        imgCover.style.backgroundColor = `${base.value}`;
        hl.style.color = `${base.value}`;
      };
    </script>
  </body>
</html>

3. 리뷰

input과 change의 차이점 : input은 실시간으로 값을 받아들이지만 change는 마지막값 즉, 결과값만 받아들인다.

 

728x90
반응형

'개발 > html, css, js' 카테고리의 다른 글

[30일 챌린지 Day-5] flex, classname 추가 활용  (0) 2022.07.25
[30일 챌린지 Day-4] 배열,객체 알고리즘  (0) 2022.07.25
[30일 챌린지 Day-2] 시계 만들기  (1) 2022.07.25
[JavaScript] 농구게임 만들기  (0) 2022.06.21
[HTML, JavaScript] 정규표현식  (0) 2022.06.21
'개발/html, css, js' 카테고리의 다른 글
  • [30일 챌린지 Day-5] flex, classname 추가 활용
  • [30일 챌린지 Day-4] 배열,객체 알고리즘
  • [30일 챌린지 Day-2] 시계 만들기
  • [JavaScript] 농구게임 만들기
TeTedo.
TeTedo.
  • TeTedo.
    TeTedo 개발 일기
    TeTedo.
  • 전체
    오늘
    어제
    • 분류 전체보기 (319)
      • 개발 (274)
        • Article (4)
        • 정리 (21)
        • Spring Boot (17)
        • JPA (2)
        • JAVA (6)
        • Database (4)
        • 자료구조 (11)
        • 알고리즘 (32)
        • React (20)
        • Docker (10)
        • node.js (18)
        • Devops (11)
        • Linux (4)
        • TypeScript (3)
        • Go (10)
        • HyperLedger (4)
        • BlockChain (43)
        • html, css, js (48)
        • CS (3)
        • AWS (3)
      • 모아두고 나중에 쓰기 (3)
      • 팀프로젝트 (18)
        • SNS(키보드워리어) (9)
        • close_sea (9)
      • 개인프로젝트 (1)
        • Around Flavor (1)
        • CHAM (13)
        • ethFruitShop (5)
      • 독서 (0)
        • 스프링부트와 AWS로 혼자 구현하는 웹 서비스 (0)
  • 블로그 메뉴

    • 홈
    • 개발일기
    • CS
    • 실습
    • 코딩테스트
    • 웹
    • Go
    • node.js
    • 팀플
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    블록체인
    컨테이너
    nodejs
    프로그래머스
    30일챌린지
    node.js
    html
    CSS
    mysql
    도커
    go
    30일 챌린지
    명령어
    js
    하이퍼레저
    go언어
    erc20
    ERC721
    node
    React
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.1
TeTedo.
[30일 챌린지 Day-3] input값 적용하기
상단으로

티스토리툴바