HTML5 캔버스로 그리기 응용 프로그램을 만들고 있습니다. 그것은 하나의 것을 받아들입니다. 드로잉은 커서에서 ~ 50px 아래/오른쪽처럼 발생합니다. 아래 코드는 내 코드입니다. 왜 이런 일이 일어나는지 말할 수 있습니까?캔버스로 그리기가 커서를 따라 가지 않습니다.
var letsdraw = false;
var theCanvas = document.getElementById('paint');
var ctx = theCanvas.getContext('2d');
theCanvas.width = 420;
theCanvas.height = 300;
$('#paint').mousemove(function(e) {
if (letsdraw === true){
ctx.strokeStyle = 'blue';
ctx.lineWidth = 100;
ctx.lineCap = 'round';
ctx.beginPath();
ctx.moveTo(e.pageX, e.pageY);
ctx.lineTo(e.pageX, e.pageY);
ctx.stroke();
}
});
$('#paint').mousedown(function(){
letsdraw = true;
});
$('#paint').mouseup(function(){
letsdraw = false;
});
답변 주셔서 감사합니다, 매력처럼 작동합니다! – holyredbeard