Live editing of RGB values ​​in rgba

I am creating a website where I want users to be able to change the color of one of the divs. The color is set using rgba because I want it to be transparent.

The problem I am facing is that I found a color picker, but I change the RGB without pressing opacity. Here's how I have it so far:

<input class="color" type="text" onchange="document.getElementById('main-info').style.backgroundColor = '#' + this.color;">

Obviously, I am replacing rgba with hex, for a live version that kills opacity. Other things I've tried:

<input class="color" type="text" onchange=" document.getElementById('id_info_box_bg_color').value = (Math.floor(this.color.rgb[0]*255)) + ', ' + (Math.floor(this.color.rgb[1]*255)) + ', ' + (Math.floor(this.color.rgb[2]*255));">

which successfully gets rgba values, but I can't get it to correctly insert into rgba.

Does anyone know how I can replace the rgba part? So I just change Xs to rgba (X, X, X, .5)

+3
source share
2 answers

, rgba, div rgba css, rgba, css:

$('#myDiv').css('background-color');

, (): "rgba (255, 0, 0, 0.496094)" , ​​ 1, "rgb (255, 0, 0)" From - , rgba. , - , (, , , .) div:

$('#myDiv').css('background-color', 'newColor');

- , , css , , -, .

+2

css

#id_info_box_bg_color {
  -ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=50)"; // ms ie 8 first!
  filter: alpha(opacity=50);                    // rest of the ie browsers second!
  opacity: .5;  // standard compliant browsers
}
+1

All Articles