1
我试图提供一个橡皮擦,就像它是一把刷子一样,可以清晰地擦除。我有一个黑色的矩形和作为画布背景的图片。我怎样才能清除rect的一部分?画布,我的橡皮擦不起作用
"Erasing" in html5 canvas,没有工作
我的小提琴:http://jsfiddle.net/FgNQk/10/
var canvas = document.getElementById('canvas');
var ctx = canvas.getContext('2d');
var width = window.innerWidth;
var height = window.innerHeight;
canvas.height = height;
canvas.width = width;
ctx.fillRect(100,100,100,100);
canvas.addEventListener('mousedown', function(e) {
this.down = true;
this.X = e.pageX ;
this.Y = e.pageY ;
this.color = rgb();
}, 0);
canvas.addEventListener('mouseup', function() {
this.down = false;
}, 0);
canvas.addEventListener('mousemove', function(e) {
if(this.down) {
with(ctx) {
beginPath();
moveTo(this.X, this.Y);
lineTo(e.pageX , e.pageY);
strokeStyle = "rgba(255,255,255,0.0)";
ctx.lineWidth=1;
stroke();
}
this.X = e.pageX ;
this.Y = e.pageY ;
}
}, 0);
我用rgb试了这么多,忘记了globalCompositeOperation,谢谢 – daisy 2013-05-13 15:36:45