Programmatically use RGBa values in fillStyle in ?

前端 未结 5 533
栀梦
栀梦 2021-01-03 17:13

Using , I want to set the RGBa value of the rectangle using a variable.

for example:

ctx.fillStyle = \"rgba(32, 45, 21, 0         


        
5条回答
  •  有刺的猬
    2021-01-03 18:05

    var r_a = 0.3
    ctx.fillStyle = `rgba(32, 45, 21, ${r_a})`;
    

    These are called template literals https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals

    The back-ticks `` are often found left of the number 1 on the keyboard on US keyboards.

提交回复
热议问题