控制台向我确认不透明度正确传播了 0 到 1 之间的值。我搜索了几个小时如何将这个变量带到函数 draw() 来更改矩形的透明度值。我将不胜感激任何指导。
$(document).ready( function() {
$('.demo').each( function() {
$(this).minicolors({
opacity: true,
change: function(hex, opacity) {
console.log(hex + ' - ' + opacity);
draw();
},
theme: 'bootstrap'
});
});
});
我需要将不透明度变量转换为 opacityVar(?)
function draw() {
ctx.save();
ctx.beginPath();
ctx.rect(0, 10, 200, 320);
ctx.fillStyle = 'rgba(77,225,77, MyOpacity';
ctx.fill();
}
你可以
像这样传递它
//draw accepts opacity as a parameter
function draw(opacity) {
ctx.save();
ctx.beginPath();
ctx.rect(0, 10, 200, 320);
ctx.fillStyle = 'rgba(77,225,77, ' + opacity + ')';
ctx.fill();
}
$(document).ready(function () {
$('.demo').each(function () {
$(this).minicolors({
opacity: true,
change: function (hex, opacity) {
console.log(hex + ' - ' + opacity);
//pass opacity as the argument
draw(opacity);
},
theme: 'bootstrap'
});
});
});