Sometimes, we want to change the opacity (alpha, transparency) of an element in a canvas element with JavaScript.
In this article, we’ll look at how to change the opacity (alpha, transparency) of an element in a canvas element with JavaScript.
How to change the opacity (alpha, transparency) of an element in a canvas element with JavaScript?
To change the opacity (alpha, transparency) of an element in a canvas element with JavaScript, we set the fillStyle
of the canvas.
For instance, we write
ctx.fillStyle = "rgba(255, 255, 255, 0.5)";
to set the fillStyle
of the canvas to the baackground color with the transparency value.
Conclusion
To change the opacity (alpha, transparency) of an element in a canvas element with JavaScript, we set the fillStyle
of the canvas.