I'm useing spectrum jQuery colorpicker and changing the background-color working properly but there's just one problem. after refreshing the page,the color of the chooser button gets black instead of selected color (for example, red) background color of the page changed without any problem and everything worked properly except that. Look at this(click to see images):
Selected Color -> after refreshing the page
This is my code:
HTML:
<input id="colorpicker" style="display: none;">
JS:
var currColor = $.cookie('body_color') || 'rgba(0, 0, 0, 0.5)';
$('body').css('background-color', currColor);
$("#colorpicker").spectrum({
preferredFormat: 'rgb',
showInput: true,
showAlpha: true,
color: currColor.substring(1),
move: function(color) {
$('body').css('background-color', color.toRgbString());
$.cookie('body_color', color.toRgbString(), {
expires: 365
});
}
});
how can I fix this?
If I change color.toRgbString()
to color.toHexString()
this issue get fixed but another issue occurs (after that I cant use rgba colors for page's background and transparency not work):
var currColor = $.cookie('body_color') || 'rgba(0, 0, 0, 0.5)';
$('body').css('background-color', currColor);
$("#colorpicker").spectrum({
preferredFormat: 'rgb',
showInput: true,
showAlpha: true,
color: currColor.substring(1),
move: function(color) {
$('body').css('background-color', color.toHexString());
$.cookie('body_color', color.toHexString(), {
expires: 365
});
}
});