JavaScript canvas2d object property: globalAlpha
[this page | pdf | back links]
The globalAlpha property of the JavaScript
DOM object returned
by the getContext("2d")
method applied to the HTML <canvas>
element sets / returns the current alpha, i.e. transparency value, of the
drawing.
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head></head>
<body>
<span id="element"></span>
<script>
var x2 = document.createElement("CANVAS");
x2.setAttribute("width","200");
x2.setAttribute("height","100");
x2.setAttribute("style","border: 1px solid black");
var c2 = x2.getContext("2d");
c2.fillStyle = "blue";
c2.fillRect(10, 10, 100, 50);
c2.globalAlpha = 0.2;
c2.fillStyle = "red";
c2.fillRect(90, 40, 100, 50);
document.getElementById("element").appendChild(x2);
</script>
</body>
</html>
|
NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)