如何在 html5 中制作透明画布? [英] How do I make a transparent canvas in html5?
本文介绍了如何在 html5 中制作透明画布?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使画布透明?我需要这样做,因为我想将两个画布叠在一起.
How can I make a canvas transparent? I need to because I want to put two canvases on top of one another.
推荐答案
默认情况下画布是透明的.
Canvases are transparent by default.
尝试设置页面背景图像,然后在其上放置画布.如果画布上什么都没画,就可以完全看到页面背景.
Try setting a page background image, and then put a canvas over it. If nothing is drawn on the canvas, you can fully see the page background.
把画布想象成在玻璃板上作画.
要在画布上绘制后清除画布,只需使用 clearRect
:
To clear a canvas after having drawn on it, just use clearRect
:
const context = canvas.getContext('2d');
context.clearRect(0, 0, canvas.width, canvas.height);
这篇关于如何在 html5 中制作透明画布?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文