这个小代码在间隔中清除旧的画布数据:
// start interval
ctx.save();
ctx.fillStyle = "rgba(0, 0, 0, 0.2)";
ctx.fillRect(0, 0, ctx.width, ctx.height);
ctx.restore();
//some draw code for new graph
...
//end interval
Run Code Online (Sandbox Code Playgroud)
我的工作区域变黑了,因为我将黑色设置为填充颜色(rgba(0,0,0,.2)),但我需要透明背景,而不是黑色.
我尝试使用globalAlpha和imagePutData,但我失败了.
我怎么能这样做?