Skip to content

Commit

Permalink
Merge pull request #75 from wanadev/fix-absolute-widget-position
Browse files Browse the repository at this point in the history
take scroll into account in absolute position calculation
  • Loading branch information
flozz authored Sep 14, 2016
2 parents 84257b2 + 8482b8a commit 3077bc6
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,12 +106,16 @@ Helpers.getAbsolutePosition = function (element) {
if (!(element instanceof Element)) {
return {x: 0, y: 0};
}

var css;
var origElement = element;

try {
css = getComputedStyle(element);
} catch (e) {
return {x: 0, y: 0};
}

if (!css) {
return {x: 0, y: 0};
}
Expand All @@ -131,6 +135,14 @@ Helpers.getAbsolutePosition = function (element) {
element = element.offsetParent;
}

element = origElement;

while (element.parentNode && !(element instanceof HTMLBodyElement)) {
x -= element.scrollLeft || 0;
y -= element.scrollTop || 0;
element = element.parentNode;
}

return {x: x, y: y};
};

Expand Down

0 comments on commit 3077bc6

Please sign in to comment.