繁体   English   中英

clearRect function 不清除 canvas

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM