globalAlpha 속성은 도면의 투명도 값을 반환합니다. 이 속성의 값 1.0은 투명도를 지정하지 않고 이 속성의 값 0.0은 전체 투명도를 지정합니다. 따라서 globalAlpha 속성을 0.0으로 설정하면 투명한 캔버스를 얻을 수 있습니다.
예시
다음 코드를 실행하여 투명한 캔버스를 만들 수 있습니다. −
<!DOCTYPE html>
<html>
<body>
<canvas id = "idCanvas" width = "400" height = "200" style = "border:2px solid #000000;">
Your browser does not support the HTML5 canvas tag.</canvas>
<script>
var c = document.getElementById("idCanvas");
var ctx = c.getContext("2d");
ctx.fillStyle = "green";
ctx.fillRect(20, 20, 75, 50);
ctx.globalAlpha = 0.0;
ctx.fillStyle = "yellow";
ctx.fillRect(50, 50, 75, 50);
ctx.fillStyle = "red";
ctx.fillRect(80, 80, 75, 50);
</script>
</body>
</html>