當您單擊codepen上的清除畫布按鈕時,它將顯示爲畫布清除,但如果您再次嘗試繪畫,所有舊線條將重新出現。畫布上的清除功能無法正常工作
//Redraw
function redraw(){
$("#clearcanvas").click(function() {
context.clearRect(0, 0, context.canvas.width, context.canvas.height);
});
context.strokeStyle = "#df4b26";
context.lineJoin = "round";
context.lineWidth = 5;
for(var i=0; i < clickX.length; i++) {
context.beginPath();
if(clickDrag[i] && i){
context.moveTo(clickX[i-1], clickY[i-1]);
}
else {
context.moveTo(clickX[i]-1, clickY[i]);
}
context.lineTo(clickX[i], clickY[i]);
context.closePath();
context.stroke();
}
}
全碼:http://codepen.io/urketadic/pen/AXGKvp