Jquery 如何将不透明度变量传递给函数draw()
控制台向我确认不透明度正确传播0和1之间的值。我花了几个小时研究如何将这个变量引入函数draw(),以更改矩形的透明度值。我希望得到任何指导Jquery 如何将不透明度变量传递给函数draw(),jquery,canvas,Jquery,Canvas,控制台向我确认不透明度正确传播0和1之间的值。我花了几个小时研究如何将这个变量引入函数draw(),以更改矩形的透明度值。我希望得到任何指导 $(document).ready( function() { $('.demo').each( function() { $(this).minicolors({ opacity: true, change: function(hex,
$(document).ready( function() {
$('.demo').each( function() {
$(this).minicolors({
opacity: true,
change: function(hex, opacity) {
console.log(hex + ' - ' + opacity);
draw();
},
theme: 'bootstrap'
});
});
});
//我需要将opacity var转换为opacityVar(?)
你可以像这样通过
//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'
});
});
});
//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'
});
});
});