使用 <canvas>
,我想使用变量设置矩形的 RGBa 值。
例如:
ctx.fillStyle = "rgba(32, 45, 21, 0.3)";
工作正常,但将其与变量一起使用:
var r_a = 0.3;
ctx.fillStyle = "rgba(32, 45, 21, r_a)";
不起作用。
显然 fillStyle
只接受一个字符串。那么如何使用一些变量而不是显式定义值来设置 rgba 值呢?
最佳答案
您只需连接 r_a
变量即可正确构建字符串:
var r_a = 0.3;
ctx.fillStyle = "rgba(32, 45, 21, " + r_a + ")";
关于javascript - 以编程方式在 <canvas> 的 fillStyle 中使用 RGBa 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1957346/