bgrins / spectrum

The No Hassle JavaScript Colorpicker
https://bgrins.github.io/spectrum/
MIT License
2.32k stars 589 forks source link

API method to set alpha channel value #447

Open temuri416 opened 8 years ago

temuri416 commented 8 years ago

Hello,

Would it be possible to create an API method to set alpha channel value?

My use case:

I let (inexperienced) users choose rectangle fill color in RGBA format which defaults to transparent. They may not realize that choosing color is not enough and they should also change alpha channel value.

Thanks!

Trixt0r commented 8 years ago

Had the same problem. It is already possible though, with a simple workaround:

let color = $yourInput.spectrum('get');
color.setAlpha(yourAlphaValue);
let rgb = color.toRgbString();
$yourInput.spectrum('set', rgb);

But it would be nice to have an API method, to save some loc ;)

-Trixt0r