私はbodyonmousemove
関数でこのスクリプトを使用しています:
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/