Skip to content

Commit

Permalink
fix(eventToViewCoord): check if event.offset properties are defined
Browse files Browse the repository at this point in the history
  • Loading branch information
mgermerie authored and gchoqueux committed Jul 29, 2021
1 parent 7f355c4 commit 26f459a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Core/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -639,15 +639,16 @@ class View extends THREE.EventDispatcher {
* @param {event} event - event can be a MouseEvent or a TouchEvent
* @param {THREE.Vector2} target - the target to set the view coords in
* @param {number} [touchIdx=0] - finger index when using a TouchEvent
* @return {THREE.Vector2} - view coordinates (in pixels, 0-0 = top-left of the View)
* @return {THREE.Vector2|undefined} - view coordinates (in pixels, 0-0 = top-left of the View).
* If the event is neither a `MouseEvent` nor a `TouchEvent`, the return is `undefined`.
*/
eventToViewCoords(event, target = _eventCoords, touchIdx = 0) {
const br = this.domElement.getBoundingClientRect();

if (event.touches && event.touches.length) {
return target.set(event.touches[touchIdx].clientX - br.x,
event.touches[touchIdx].clientY - br.y);
} else if (event.offsetX && event.offsetY) {
} else if (event.offsetX !== undefined && event.offsetY !== undefined) {
const targetBoundingRect = event.target.getBoundingClientRect();
return target.set(targetBoundingRect.x + event.offsetX - br.x,
targetBoundingRect.y + event.offsetY - br.y);
Expand Down

0 comments on commit 26f459a

Please sign in to comment.