[英]How to make a transparent canvas without error?
I'm trying to get the background of a html5-starfield transparent.But why error? 我试图让html5-starfield的背景透明。但为什么会出错呢?
This with background color black http://www.thediscopalace.com/testing.php 这与背景颜色黑色http://www.thediscopalace.com/testing.php
And this if background transparent http://www.thediscopalace.com/testing1.php 这个如果背景透明http://www.thediscopalace.com/testing1.php
I change context.fillStyle='rgb(36,14,118)';
我改变了context.fillStyle='rgb(36,14,118)';
= BLACK to context.fillStyle='rgba(36,14,118, 0)';
= BLACK to context.fillStyle='rgba(36,14,118, 0)';
= TRANSPARENT =透明
The problem is in fact, that actually you're not cleaning the canvas before drawing new stars state. 问题实际上是,在绘制新星状态之前,实际上你并没有清理画布。 So you just need to change context.fillRect(0,0,w,h)
inside anim()
function to context.clearRect(0,0,w,h)
. 所以,你只需要改变context.fillRect(0,0,w,h)
内anim()
函数来context.clearRect(0,0,w,h)
It was working initially, because canvas was filled with opaque color each time new stars state were drawn, but after your changes that color become transparent. 它最初是有效的,因为每次绘制新星状态时画布都会填充不透明的颜色,但是在您更改之后颜色变得透明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.