如何在 HTML5 中建立一個透明畫布?
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>
廣告
資料結構
網路
關係資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
JavaScript
PHP