const canvas = document.getElementById('drawing-board'); const ctx = canvas.getContext('2d'); const canvasOffsetX = canvas.offsetLeft; const canvasOffsetY = canvas.offsetTop; canvas.width = window.innerWidth - canvasOffsetX * 2; canvas.height = window.innerHeight - canvasOffsetY * 2; let isPainting = false; let lineWidth = 5; let startX; let startY; ctx.strokeStyle = "skyblue"; const draw = (e) => { console.log(e); if (!isPainting) { return; } ctx.lineWidth = lineWidth; ctx.lineCap = 'round'; ctx.lineTo(e.pageX - canvasOffsetX, e.pageY - canvasOffsetY); ctx.stroke(); } canvas.addEventListener('mousedown', (e) => { isPainting = true; }); canvas.addEventListener('mouseup', (e) => { isPainting = false; ctx.stroke(); ctx.beginPath(); }); canvas.addEventListener('mousemove', draw);