Make Util.getPosition be relative to page

Commit 5108c4635c 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.
This commit is contained in:
Solly Ross 2015-02-25 17:02:16 -05:00
parent 20d3fb6665
commit 7e54fb93dd
1 changed files with 1 additions and 1 deletions

View File

@ -436,7 +436,7 @@ Util.load_scripts = function (files) {
Util.getPosition = function(obj) { Util.getPosition = function(obj) {
"use strict"; "use strict";
var objPosition = obj.getBoundingClientRect(); var objPosition = obj.getBoundingClientRect();
return {'x': objPosition.left, 'y': objPosition.top}; return {'x': objPosition.left + window.pageXOffset, 'y': objPosition.top + window.pageYOffset};
}; };