Advertisement
asimryu

hsla 컬러코드 확인 JavaScript 프로그램

Feb 11th, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.36 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.  <meta charset="UTF-8">
  5.  <title>Color Change</title>
  6.  <style>
  7.   .row > div {
  8.    float:left;
  9.    width: 25%;
  10.    text-align: center;
  11.   }
  12.   .colorbox {
  13.    clear: both;
  14.    margin-bottom: 20px;
  15.    height: 100px;
  16.    background-image: url(http://placeimg.com/1000/100/any);
  17.    background-size: cover;
  18.   }
  19.   .colorview {
  20.    height: 100px;
  21.   }
  22.  </style>
  23. </head>
  24. <body>
  25.  <div class="colorbox"><div class="colorview"></div></div>
  26.  <div class="row">
  27.   <div>
  28.    <h2>HUE</h2>
  29.    <div>0 <input type="range" name="hue" id="hue" min="0" max="260"> 360</div>
  30.    <div id="hue_value"></div>
  31.   </div>  
  32.   <div>
  33.    <h2>SATURATION</h2>
  34.    <div>0% <input type="range" name="saturation" id="saturation" min="0" max="100"> 100%</div>
  35.    <div id="saturation_value"></div>
  36.   </div>  
  37.   <div>
  38.    <h2>LIGHTNESS</h2>
  39.    <div>0% <input type="range" name="lightness" id="lightness" min="0" max="100"> 100%</div>
  40.    <div id="lightness_value"></div>
  41.   </div>  
  42.   <div>
  43.    <h2>ALPHA</h2>
  44.    <div>0 <input type="range" name="alpha" id="alpha" min="0" max="1" step="0.1"> 1</div>
  45.    <div id="alpha_value"></div>
  46.   </div>  
  47.  </div>
  48.  <script>
  49.   var colorview = document.querySelector(".colorview");
  50.   var hue = document.querySelector("#hue");
  51.   var saturation = document.querySelector("#saturation");
  52.   var lightness = document.querySelector("#lightness");
  53.   var alpha = document.querySelector("#alpha");
  54.  
  55.   hue.addEventListener("input", function(){ setColors(); });
  56.   saturation.addEventListener("input", function(){ setColors(); });
  57.   lightness.addEventListener("input", function(){ setColors(); });
  58.   alpha.addEventListener("input", function(){ setColors(); });
  59.  
  60.   function setColors() {
  61.    var hueValue = hue.value;
  62.    var saturationValue = saturation.value;
  63.    var lightnessValue = lightness.value;
  64.    var alphaValue = alpha.value;
  65.    document.querySelector("#hue_value").innerHTML = hueValue;
  66.    document.querySelector("#saturation_value").innerHTML = saturationValue + "%";
  67.    document.querySelector("#lightness_value").innerHTML = lightnessValue + "%";
  68.    document.querySelector("#alpha_value").innerHTML=alphaValue;
  69.    colorview.style.backgroundColor = "hsla(" + hueValue + "," + saturationValue + "%," + lightnessValue + "%," + alphaValue + ")";
  70.   }
  71.  
  72.   window.onload = function(){
  73.    setColors();
  74.   };
  75.  </script>
  76. </body>
  77. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement