เดอะ โกลบอลอัลฟ่า คุณสมบัติส่งคืนค่าความโปร่งใสของการวาดภาพ ค่า 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>