Hello I am trying to get the offsetX,Y of touch event which should be identical to offsetX of mouse event. To do so I have used this code:
ev.offsetX = ev.targetTouches[0].pageX- canvasName.offsetLeft
I have even tried to simulate the touch event into mouse event but for that purpose i need the offsetX/Y, which is unavailable in touch event. Is there any way offsetX/Y can be calculated for touch? Please help
I use this
var rect = e.target.getBoundingClientRect(); var x = e.targetTouches[0].pageX - rect.left; var y = e.targetTouches[0].pageY - rect.top;
The best answer here don't work for me, on webpage with scrolling! This will work better:
var bcr = e.target.getBoundingClientRect(); var x = e.targetTouches[0].clientX - bcr.x; var y = e.targetTouches[0].clientY - bcr.y;
I used it to solve my problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With