Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Transparency with events #172

Closed
ghost opened this issue Aug 4, 2016 · 5 comments
Closed

Transparency with events #172

ghost opened this issue Aug 4, 2016 · 5 comments

Comments

@ghost
Copy link

ghost commented Aug 4, 2016

Not sure if there is already a fix for this but when I have a color changer that changes the background for a div, the transparency factor doesn't work. It converts the background color to rgb, but not rgba.

@carlosvidal
Copy link

Same problem here. SetValue don't work with RGBA

@itsjavi
Copy link
Owner

itsjavi commented Oct 5, 2016

@WansonSwanson please could you provide an example as it's said in CONTRIBUTING.md ? Thanks

@carlosvidal
Copy link

`$("#myPicker").colorpicker('setValue', 'rgba(255,0,0,.5)');

$("#myPicker").colorpicker().on('changeColor', function(ev) {
$("#pie").css({
"background-color" : $("#myPicker").colorpicker('getValue'),
});
});`

@emileber
Copy link

emileber commented Oct 6, 2016

@carlosvidal it works for me. The only thing is that if the alpha was never set, it returns a hex value by default, even if the format has been specified otherwise.

To be sure, you could use the color object:

var $picker = $("#myPicker"),
    $pie = $("#pie");
$picker.colorpicker('setValue', 'rgba(255,0,0,.5)');

$picker.on('changeColor', function(ev) {
    var c = ev.color.toRGB(); // returns a RGBA hash
    $pie.css({
        "background-color": "rgba(" + c.r + ", " + c.g + ", " + c.b + ", " + c.a + ")",
    });
});

@carlosvidal
Copy link

Works perfectly. Thanks

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants