Get hsl color with javascript

荒凉一梦 提交于 2020-01-02 09:18:12

问题


If I have this:

.box{
  color: #FF3010;
  background: hsl(0,90%,40%);
}

and then this:

var box = document.querySelector(".box");
var result = document.querySelector(".result");
result.innerHTML = "BG color: "+window.getComputedStyle(box).backgroundColor;
result.innerHTML += "<br>";
result.innerHTML += "color:"+window.getComputedStyle(box).color;

The problem is that it always prints the values in rgb. So, I have 2 questions:

  1. Is it posible to get the value as written in the css?
  2. Is it posible to force the color to be hsl instead of rgb?

来源:https://stackoverflow.com/questions/30440423/get-hsl-color-with-javascript

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!