Spectrum colorpicker get color with transparency

user1544337 picture user1544337 · Mar 12, 2013 · Viewed 7.6k times · Source

I use the jQuery plugin Spectrum for a color picker:

$('#backgroundColorPicker').spectrum({
    color: '#000',
    showAlpha: true,
    move: function(color){
        $('#result').css('background-color',color.toHexString());
    }
});

See this code in action here: http://jsfiddle.net/UkmXM/1/.

As you can see I set showAlpha to true to enable a transparent background. However, I don't get a transparent background.

Answer

user1544337 picture user1544337 · Mar 12, 2013

A hex string doesn't support transparency. Use color.toRgbString() instead: http://jsfiddle.net/UkmXM/2/

$('#backgroundColorPicker').spectrum({
    color: '#000',
    showAlpha: true,
    move: function(color){
        $('#result').css('background-color',color.toRgbString());
    }
});