Skip to content

Commit

Permalink
[fixed] incorrect page offset
Browse files Browse the repository at this point in the history
  • Loading branch information
jquense committed Mar 18, 2016
1 parent e60e47d commit 18c0234
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Selection.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,8 @@ export function getBoundsForNode(node) {
if (!node.getBoundingClientRect) return node;

var rect = node.getBoundingClientRect()
, left = rect.left + (document.body.scrollLeft || 0)
, top = rect.top + (document.body.scrollTop || 0);
, left = rect.left + pageOffset('left')
, top = rect.top + pageOffset('top');

return {
top,
Expand All @@ -235,4 +235,10 @@ export function getBoundsForNode(node) {
};
}

function pageOffset(dir) {
if (dir === 'left')
return (window.pageXOffset || document.body.scrollLeft || 0)
if (dir === 'top')
return (window.pageYOffset || document.body.scrollTop || 0)
}
export default Selection

0 comments on commit 18c0234

Please sign in to comment.