这段小代码会在间隔期内清除旧的画布数据:
// 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
我的工作区变成了黑色,因为我将黑色设置为填充颜色(rgba(0, 0, 0, .2)
),但我需要一个透明的背景,而不是黑色。
我尝试使用globalAlpha
和imagePutData
,但失败了。
我该怎么做?
ctx.globalCompositeOperation = 'destination-out'
然后进行绘制? - c69