From 25d25db428330037cb4aa0529e672928ec776e84 Mon Sep 17 00:00:00 2001 From: Alexander Bazo Date: Tue, 27 Aug 2019 14:44:41 +0200 Subject: [PATCH] Use page offset to calculate target coordinates --- resources/js/game/GazePoint.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/resources/js/game/GazePoint.js b/resources/js/game/GazePoint.js index 9ec880c..ec5a239 100644 --- a/resources/js/game/GazePoint.js +++ b/resources/js/game/GazePoint.js @@ -9,14 +9,19 @@ class GazePoint { linkTo(node) { let bb = node.getBoundingClientRect(), + elementLeft = window.pageXOffset + bb.left, + elementTop = window.pageYOffset + bb.top, + elementRight = window.pageXOffset + bb.right, + elementBottom = window.pageYOffset + bb.bottom, coordinates; - if (this.screenX >= bb.left && this.screenX <= bb.right && this.screenY >= - bb.top && this.screenY <= bb.bottom) { - this.hasLink = true; - this.link = node; - this.targetX = this.screenX - bb.left; - this.targetY = this.screenY - bb.top; - } + if (this.screenX >= elementLeft && this.screenX <= elementRight && this + .screenY >= + elementTop && this.screenY <= elementBottom) { + this.hasLink = true; + this.link = node; + this.targetX = this.screenX - elementLeft; + this.targetY = this.screenY - elementTop; + } return coordinates; } -- libgit2 0.26.0