From 7e54fb93dd60f4cb08685a3a747f8f0a691519cf Mon Sep 17 00:00:00 2001 From: Solly Ross Date: Wed, 25 Feb 2015 17:02:16 -0500 Subject: [PATCH] Make Util.getPosition be relative to page Commit 5108c4635c847de9be0edadf572f7426f351b66a caused a regression in the case where scrolling is used -- getPosition return position relative to the viewport, while getEventPosition expected a position relative to the page. As per https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect, the fix for this is simply to add the `pageXOffset` and `pageYOffset` to the output of `getBoundingClientRect()`. Fixes #459. --- include/util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/util.js b/include/util.js index 482b10c9..effb0705 100644 --- a/include/util.js +++ b/include/util.js @@ -436,7 +436,7 @@ Util.load_scripts = function (files) { Util.getPosition = function(obj) { "use strict"; var objPosition = obj.getBoundingClientRect(); - return {'x': objPosition.left, 'y': objPosition.top}; + return {'x': objPosition.left + window.pageXOffset, 'y': objPosition.top + window.pageYOffset}; };