diff --git a/lib/custom-element/api/base-api.js b/lib/custom-element/api/base-api.js index 0ab3fdcc..9e42aad8 100644 --- a/lib/custom-element/api/base-api.js +++ b/lib/custom-element/api/base-api.js @@ -6,7 +6,7 @@ */ class BaseAPI { static get privateMethods() { - return [`constructor`, `addListeners`, `getMouseCoords`] + return [`constructor`, `addListeners`, `getCursorCoords`] .concat(this.superCallers) .concat(this.eventHandlers); } @@ -89,9 +89,15 @@ class BaseAPI { /** * */ - getMouseCoords(evt) { - this.cursor.x = evt.offsetX; - this.cursor.y = evt.offsetY; + getCursorCoords(evt) { + if (e.targetTouches) { + const rect = e.target.getBoundingClientRect(); + this.cursor.x = e.targetTouches[0].pageX - rect.left; + this.cursor.y = e.targetTouches[0].pageY - rect.top; + } else { + this.cursor.x = evt.offsetX; + this.cursor.y = evt.offsetY; + } } /** @@ -101,7 +107,7 @@ class BaseAPI { stop(evt); this.cursor.button = evt.button; this.cursor.down = true; - this.getMouseCoords(evt); + this.getCursorCoords(evt); } /** @@ -111,7 +117,7 @@ class BaseAPI { stop(evt); this.cursor.button = undefined; this.cursor.move = true; - this.getMouseCoords(evt); + this.getCursorCoords(evt); } /** @@ -122,7 +128,7 @@ class BaseAPI { this.cursor.button = evt.button; this.cursor.down = false; this.cursor.move = false; - this.getMouseCoords(evt); + this.getCursorCoords(evt); } /**