From 246e23a9ec38f38d103af50c3db199607483ab73 Mon Sep 17 00:00:00 2001 From: Glenn <33450392+glenn2223@users.noreply.github.com> Date: Thu, 19 May 2022 16:42:55 +0100 Subject: [PATCH] Fix for scrollable element Applied a fix when an anchor element is inside a scrollable element --- src/index.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/index.ts b/src/index.ts index cef69ed..d61321e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -81,6 +81,17 @@ export class HoverPosition { const originalDisplay = options.target.style.display; options.target.style.display = 'block'; + if (options.anchor instanceof HTMLElement) { + let parent = options.anchor.parentElement; + + while (parent !== null && parent.tagName !== "BODY") { + this._anchorDims.top -= parent.scrollTop; + this._anchorDims.left -= parent.scrollLeft; + + parent = parent.parentElement; + } + } + this._hoverBoxDims = { height: options.target.offsetHeight, width: options.target.offsetWidth,