I’m using Bootstrap Colorpicker in my Rails project and wanted to get the alpha in my JavaScript function. Does anyone know how to do this? I can easily get the color from the picker as illustrated in the example as:
$(function(){
var bodyStyle = document.getElementById('body').style;
$('#cp4').colorpicker().on('changeColor', function(ev){
bodyStyle.backgroundColor = ev.color.toHex();
});
});
You can get the alpha value as easily 🙂 You have it in the color object:
ev.color.value.aI set up a fiddle illustrating this. The code looks as follows:
The
alphavariable is anumberwith the alpha value of the selected color.