通過一些starnge原因,它不工作,我做我如何清除畫布?
canvas.width = canvas.width;
這裏是我的代碼:
function startDraw(){
document.getElementById('PaintArea').setAttribute('onmousemove', 'getMouse(event)');
}
function stopDraw(){
document.getElementById('PaintArea').setAttribute('onmousemove', '');
}
function Paint(){
var Size = document.getElementById('Size').value;
var Opacity = document.getElementById('opa').value;
var color = document.getElementById('color').value;
canvas = document.getElementById('PaintArea');
if(canvas.getContext){
var ctx = canvas.getContext('2d');
ctx.fillStyle = color;
ctx.globalAlpha = Opacity;
ctx.beginPath();
ctx.arc(musX-10, musY-10, Size, 0, Math.PI*2);
ctx.closePath();
ctx.fill();
}
}
function clear(){
canvas.width = canvas.width;
}
function getMouse(event) {
musY = event.clientY;
musX = event.clientX;
Paint();
}
按鈕:
<button onclick="clear()">Clear</button>
在它說的鉻控制檯
: 「document.clear()已被棄用,這種方法不會做任何事情。」
我也有這些全球varables:
var musX;
var musY;
var canvas;
同樣的原因及解決辦法,因爲我在http://stackoverflow.com/a/9160009/855543 – PointedEars