I need a color converter to convert from hsl to rgb and hex value. I am going to do similar like this. I am using jquery and jquery ui range slider for this. Here is my co
Another way to solve this problem is to leverage the window.getComputedStyle capability of modern browsers:
Create an element on the page (it can be hidden, e.g. with display:none
, but that appears to suppress output of the opacity / "A" value)
Set a color-valued property of that element using the representation of your choice, e.g. e.style.color = 'hsla(100, 50%, 75%, 0.8)';
(or even named colors like 'rebeccapurple'
)
Read the value back using window.getComputedStyle(e).color
. It will be a string of the form rgb(r,g,b)
or rgba(r,g,b,a)
.
Live demo on CodePen