[英]clearRect function doesn't clear the canvas
我在正文onmousemove
function 上使用這個腳本:
function lineDraw() {
// Get the context and the canvas:
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
// Clear the last canvas
context.clearRect(0, 0, canvas.width, canvas.height);
// Draw the line:
context.moveTo(0, 0);
context.lineTo(event.clientX, event.clientY);
context.stroke();
}
每次我移動鼠標並畫一條新線時,它應該清除 canvas,但它不能正常工作。 我試圖在不使用 jQuery、鼠標偵聽器或類似設備的情況下解決它。
這是一個演示: https://jsfiddle.net/0y4wf31k/
我在body onmousemove
函數上使用此腳本:
function lineDraw() {
// Get the context and the canvas:
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
// Clear the last canvas
context.clearRect(0, 0, canvas.width, canvas.height);
// Draw the line:
context.moveTo(0, 0);
context.lineTo(event.clientX, event.clientY);
context.stroke();
}
每次我移動鼠標並畫一條新線時,都應該清除畫布,但是它不能正常工作。 我正在嘗試不使用jQuery,鼠標偵聽器或類似工具來解決它。
這是一個演示: https : //jsfiddle.net/0y4wf31k/
我在body onmousemove
函數上使用此腳本:
function lineDraw() {
// Get the context and the canvas:
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
// Clear the last canvas
context.clearRect(0, 0, canvas.width, canvas.height);
// Draw the line:
context.moveTo(0, 0);
context.lineTo(event.clientX, event.clientY);
context.stroke();
}
每次我移動鼠標並畫一條新線時,都應該清除畫布,但是它不能正常工作。 我正在嘗試不使用jQuery,鼠標偵聽器或類似工具來解決它。
這是一個演示: https : //jsfiddle.net/0y4wf31k/
我在body onmousemove
函數上使用此腳本:
function lineDraw() {
// Get the context and the canvas:
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
// Clear the last canvas
context.clearRect(0, 0, canvas.width, canvas.height);
// Draw the line:
context.moveTo(0, 0);
context.lineTo(event.clientX, event.clientY);
context.stroke();
}
每次我移動鼠標並畫一條新線時,都應該清除畫布,但是它不能正常工作。 我正在嘗試不使用jQuery,鼠標偵聽器或類似工具來解決它。
這是一個演示: https : //jsfiddle.net/0y4wf31k/
我在body onmousemove
函數上使用此腳本:
function lineDraw() {
// Get the context and the canvas:
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
// Clear the last canvas
context.clearRect(0, 0, canvas.width, canvas.height);
// Draw the line:
context.moveTo(0, 0);
context.lineTo(event.clientX, event.clientY);
context.stroke();
}
每次我移動鼠標並畫一條新線時,都應該清除畫布,但是它不能正常工作。 我正在嘗試不使用jQuery,鼠標偵聽器或類似工具來解決它。
這是一個演示: https : //jsfiddle.net/0y4wf31k/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.