如何在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>热门推荐
5 薛之谦祝福语简短
10 祝福语简短七夕
11 18岁的祝福语简短
12 小孩想说的祝福语简短
13 生日祝福语简短明了 同事
14 新年祝福语长辈简短红包
15 初八的祝福语简短
16 英文简短唯美祝福语大全
17 高考已上岸祝福语简短
18 给儿子生日祝福语 简短