ivanvmat / color-picker

:droplet: Flat and simple color-picker library. No dependencies, no jquery.
https://ivanvmat.github.io/color-picker/
MIT License
20 stars 5 forks source link

How can you directly set the picker to a colour in the front end? #3

Closed mango-unchained closed 3 years ago

mango-unchained commented 3 years ago

Hi, Ivan. The script is great, but I'm trying to set the picker to a certain colour value when it opens. Is there a way to do this? I've been throwing arguments into picker.update, but so far nothing has worked. Thanks.

ivanvmat commented 3 years ago

Hi,

I added color option to the configuration. const picker = new ColorPickerControl({ container: document.body, color: { r: 255, g: 255, b: 255 } }); This should solve your problem.

Renato-Sanchez commented 3 years ago

Hi, mango, for dynamic updates, I use the following code (using the same demo as the repository):

//control update color_pickers.forEach(color_picker => { color_pickers.filter(p=>p!=color_picker).forEach((p) => { p.color.fromRGBa(new-red , new-green , new-blue , new-alpha); p.update(false); }); });

mango-unchained commented 3 years ago

Thanks for the responses, guys, and thanks so much, Ivan, for the update. You're a legend!