Skip to content

Commit

Permalink
Merge pull request #1679 from tmarti/fix-mouse-canvas-pos-query
Browse files Browse the repository at this point in the history
[IMPROVEMENT]: Simpler and more robust obtention of mouse canvas coordinates
  • Loading branch information
xeolabs authored Sep 25, 2024
2 parents b486f79 + e34a492 commit 260b66c
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/viewer/scene/input/Input.js
Original file line number Diff line number Diff line change
Expand Up @@ -1300,15 +1300,11 @@ class Input extends Component {
this.mouseCanvasPos[1] = event.y;
} else {
let element = event.target;
let totalOffsetLeft = 0;
let totalOffsetTop = 0;
while (element.offsetParent) {
totalOffsetLeft += element.offsetLeft;
totalOffsetTop += element.offsetTop;
element = element.offsetParent;
}
this.mouseCanvasPos[0] = event.pageX - totalOffsetLeft;
this.mouseCanvasPos[1] = event.pageY - totalOffsetTop;

const rect = element.getBoundingClientRect();

this.mouseCanvasPos[0] = event.clientX - rect.left;
this.mouseCanvasPos[1] = event.clientY - rect.top;
}
}

Expand Down

0 comments on commit 260b66c

Please sign in to comment.