Explorar o código

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.
Solly Ross %!s(int64=11) %!d(string=hai) anos
pai
achega
7e54fb93dd
Modificáronse 1 ficheiros con 1 adicións e 1 borrados
  1. 1 1
      include/util.js

+ 1 - 1
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};
 };