diff --git a/src/DragDropTouch.js b/src/DragDropTouch.js index fafa035..a59fcbd 100644 --- a/src/DragDropTouch.js +++ b/src/DragDropTouch.js @@ -298,18 +298,13 @@ export default () => { // if target element is an iframe, try propagating event to child element if (el && el.nodeName === 'IFRAME') { try { - var iframeDocument = el.contentWindow.document; - // get iframe absolute offset - var iframeAbsoluteOffset = { x: 0, y: 0 }; - do { - iframeAbsoluteOffset.x += el.offsetLeft || 0; - iframeAbsoluteOffset.y += el.offsetTop || 0; - el = el.offsetParent; - } while (el); + // get iframe absolute offset relative to viewport + var rect = el.getBoundingClientRect(); // remove iframe absolute offset from touch position - var x = pt.x - iframeAbsoluteOffset.x, - y = pt.y - iframeAbsoluteOffset.y; + var x = pt.x - rect.x, + y = pt.y - rect.y; // get element on that position from iframe document + var iframeDocument = el.contentWindow.document; el = iframeDocument.elementFromPoint(x, y); } catch (e) { // iframe origin don't allow access