Reputation: 61
I'm using spectrum color picker jquery plugin, I'm trying to set the color and alpha value to the plugin but by default when color picker opens and does not selects the color and alpha in the roller, by default it selects left corner color.
$container.find('#color-palette').spectrum({
color: 'rgba(136, 171, 145, 0.5)',
flat: true,
showInput: false,
showAlpha: true,
showSelectionPalette: false,
showButtons: false,
showInput: true
});
In th above example i have passed color value with alpha value, but it doesn't set the passed value in color picker.
If any have suggestion please reply to this.
Thanks, Gopi
Upvotes: 0
Views: 2239
Reputation: 21
So I recently had the exact same issue. What I found was the calculation for the color picker was being done before the color picker was visible on screen, meaning the picker's height and width were not set which was causing it to default to the top left corner. If your color picker is hidden, being animated, or not visible when it's being initialized or when the color is being set, this bug will happen.
The solution is to tell the color picker to reflow after it is visible. This is the command:
$container.spectrum("reflow");
Here's the documentation for it.
Where you put the above line will depend on where your container is being initialized and what state it is in when you do, but try to put it somewhere where you're sure the color picker is visible and has it's height and width already calculated.
Upvotes: 2