1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-09-25 15:49:06 +02:00

touch coordinate fix

This commit is contained in:
Pomax
2020-08-08 12:29:12 -07:00
parent 89c7fe9d93
commit 9bc1749b35

View File

@@ -90,13 +90,19 @@ class BaseAPI {
* *
*/ */
getCursorCoords(evt) { getCursorCoords(evt) {
const left = evt.target.offsetLeft,
top = evt.target.offsetTop;
if (evt.targetTouches) { if (evt.targetTouches) {
const rect = evt.target.getBoundingClientRect(); const touch = evt.targetTouches;
this.cursor.x = evt.targetTouches[0].pageX - rect.left; for (let i=0; i<touch.length; i++) {
this.cursor.y = evt.targetTouches[0].pageY - rect.top; if (!touch[i] || !touch[i].pageX) continue;
this.cursor.x = touch[i].pageX - left;
this.cursor.y = touch[i].pageY - top;
break;
}
} else { } else {
this.cursor.x = evt.offsetX; this.cursor.x = evt.pageX - left;
this.cursor.y = evt.offsetY; this.cursor.y = evt.pageY - top;
} }
} }