Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When VueDrawingCanvas is wrapped in another component, drawing offset is wrong #31

Open
abesic-starke opened this issue Jan 22, 2023 · 2 comments

Comments

@abesic-starke
Copy link

abesic-starke commented Jan 22, 2023

Before I started using your VueDrawingCanvas I tried to create my own canvas and got it working, but couldn't get touch to work and I had encountered this offset problem too.

I had this issue because I used the mouse position to draw instead of the position of the mouse relative to the canvas element...
I accomplished it by creating this code, as you can see I use mouseCanvasX and Y instead of e.clientX directly:

`
const draw = (e) => {
const rect = canvas.getBoundingClientRect();
let mouseCanvasX = (e.clientX - rect.left) / (rect.right - rect.left) * canvas.width;
let mouseCanvasY = (e.clientY - rect.top) / (rect.bottom - rect.top) * canvas.height;

  ctx.lineTo(mouseCanvasX, mouseCanvasY);
  ctx.stroke();
}

`

drawing canvas bug

@Hewsman
Copy link

Hewsman commented Aug 4, 2023

I have this problem as well, my current solution is to just use overflow scroll - and let user scroll if the canvas is larger than the viewport

@Krxplx
Copy link

Krxplx commented Aug 17, 2023

I have this problem as well, any updates? I need my canvas to be responsive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants