Skip to content

Commit

Permalink
[FIX] #2 :: 좌표 값 초기화를 clientX로 하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
jongeuni committed Apr 26, 2022
1 parent 4d363ff commit 2e20104
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions rancuft/src/components/DrawGift/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,29 @@ function DrowGift() {
drawing = true;
var rect = canvas.current.getBoundingClientRect();
ctx.fillStyle = 'red';
console.log('ctx true')
}
}

const handlerMouseUp = e => {
if(ctx) {
drawing = false;
console.log('음 ')
}
}

const draw = e => {
const x = e.offsetX;
const y = e.offsetY;

const x = e.clientX;
const y = e.clientY;
if (!drawing) return;
console.log('tt');

ctx.strokeStyle = "red";
ctx.lineWidth = 5;
ctx.lineJoin = 'round';

ctx.beginPath();
ctx.moveTo(x, y);
ctx.lineTo(x, y);
ctx.closePath();
ctx.stroke();
}

Expand All @@ -58,7 +62,7 @@ function DrowGift() {
<S.DrawBox>
<canvas
ref={canvas}
width={800} height={800}
width={400} height={350}
onMouseDown={handlerMouseDown}
onMouseUp={handlerMouseUp}
onMouseMove = {draw}>이 브라우저는 캔버스를 지원하지 않습니다 😅<br/> 선물 받아보기는 어떠신가요?</canvas>
Expand Down

0 comments on commit 2e20104

Please sign in to comment.