Skip to content

Commit 18c0234

Browse files
committed
[fixed] incorrect page offset
fixes jquense#55
1 parent e60e47d commit 18c0234

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/Selection.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ export function getBoundsForNode(node) {
224224
if (!node.getBoundingClientRect) return node;
225225

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

230230
return {
231231
top,
@@ -235,4 +235,10 @@ export function getBoundsForNode(node) {
235235
};
236236
}
237237

238+
function pageOffset(dir) {
239+
if (dir === 'left')
240+
return (window.pageXOffset || document.body.scrollLeft || 0)
241+
if (dir === 'top')
242+
return (window.pageYOffset || document.body.scrollTop || 0)
243+
}
238244
export default Selection

0 commit comments

Comments
 (0)