From 18c0234231b4cb68ec523f96126cb787ec6ccbe6 Mon Sep 17 00:00:00 2001 From: Jason Quense Date: Fri, 18 Mar 2016 09:47:15 -0400 Subject: [PATCH] [fixed] incorrect page offset fixes #55 --- src/Selection.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Selection.js b/src/Selection.js index 63592a145..f0517f5f0 100644 --- a/src/Selection.js +++ b/src/Selection.js @@ -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, @@ -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