simonwep / pickr

🎨 Flat, simple, multi-themed, responsive and hackable Color-Picker library. No dependencies, no jQuery. Compatible with all CSS Frameworks e.g. Bootstrap, Materialize. Supports alpha channel, rgba, hsla, hsva and more!
https://simonwep.github.io/pickr
MIT License
4.31k stars 285 forks source link

Change hex to rgba when alpha is changed #219

Open anthonyryanrusso opened 4 years ago

anthonyryanrusso commented 4 years ago

Is it possible for a the picker to start with a hex value and then change to rgba when the alpha is changed?

E.g. the pickr starts off as #ffffff but the alpha is changed to .8 so now the pickr displays it as rgba(255, 255, 255, .8)

simonwep commented 4 years ago

You could listen for the change event, check if the color has an alpha value and change the representation with setColorRepresentation to RGBA

CodeExplore commented 3 years ago

It means:

// pickr is your instance.
pickr.on('change', function( color ) {
   if ( color.a === 1 ) {
    pickr.setColorRepresentation('HEX');
  } else {
    pickr.setColorRepresentation('RGBA');
  }
});