What is the problem of mouse misplacement in canvas?

I implemented a scratch card component effect with canvas
but there is a bug
quasi-basket mouse position
smear position is correct when the mouse position is on the right edge
there is a shift when the mouse position is on the left edge, as shown
my code is as follows:

this.context.arc(touch.pageX - this.canvas.offsetLeft, touch.pageY - this.canvas.getBoundingClientRect().top + 10, 20, 0, Math.PI * 2);

what is the reason for the shift? Also look at the correction, thank you

Jul.11,2022

let bounding = this.canvas.getBoundingClientRect()
this.context.arc(touch.clientX - bounding.left, touch.clientY - bounding.top + 10, 20, 0, Math.PI * 2)

try to see if it works

Menu