---
title: "Comment by Frendhi on \"JavaScript mouse drawing on the canvas 👨‍🎨\" | Hashnode"
description: "Great article! Thanks! I&#39;ve made the &quot;fixed-width&quot; version, by setting the canvas size to copy it&#39;s parent wrapper&#39;s size. ctx.canvas.widt"
url: "https://hashnode.com/posts/javascript-mouse-drawing-on-the-canvas/5f7d5154eba2f86adc0b6465/comment/5f7d8e2494f39f6ab9fbfdf3"
---

[Discussion](https://hashnode.com/posts/javascript-mouse-drawing-on-the-canvas/5f7d5154eba2f86adc0b6465)

Comment [JavaScript mouse drawing on the canvas 👨‍🎨](https://hashnode.com/posts/javascript-mouse-drawing-on-the-canvas/5f7d5154eba2f86adc0b6465)

[Frendhi](https://hashnode.com/@fsdnr)

[Oct 7, 2020](https://hashnode.com/posts/javascript-mouse-drawing-on-the-canvas/5f7d5154eba2f86adc0b6465/comment/5f7d8e2494f39f6ab9fbfdf3)

Great article! Thanks! I've made the "fixed-width" version, by setting the canvas size to copy it's parent wrapper's size.

```
  ctx.canvas.width = canvas.offsetWidth;
  ctx.canvas.height = canvas.offsetHeight;
```

[codepen.io/frendhisaido\_1470415284/pen/dyXypKB](https://codepen.io/frendhisaido_1470415284/pen/dyXypKB)

But I'm still not sure why if the canvas is inside any parent that has a relative position, the mouse draw precision will be off by a few pixels.

[Chris Bongers](https://hashnode.com/@dailydevtips)

[Oct 7, 2020](https://hashnode.com/posts/javascript-mouse-drawing-on-the-canvas/5f7d5154eba2f86adc0b6465/comment/5f7d8e2494f39f6ab9fbfdf3#reply-5f7da6e2eba2f86adc0b68ea)

Awesome, yes that's the way to go, you mean the line is 1px ahead of your cursor? I think it's because the line is thick, so it sets the pointer inside the line.
