Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit 95536b4

Browse files
authored
Fix for scrollable element - PR #5 from glenn2223
Fixed position output when an anchor element is inside a scrollable element
2 parents dba1482 + 246e23a commit 95536b4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ export class HoverPosition {
8181
const originalDisplay = options.target.style.display;
8282
options.target.style.display = 'block';
8383

84+
if (options.anchor instanceof HTMLElement) {
85+
let parent = options.anchor.parentElement;
86+
87+
while (parent !== null && parent.tagName !== "BODY") {
88+
this._anchorDims.top -= parent.scrollTop;
89+
this._anchorDims.left -= parent.scrollLeft;
90+
91+
parent = parent.parentElement;
92+
}
93+
}
94+
8495
this._hoverBoxDims = {
8596
height: options.target.offsetHeight,
8697
width: options.target.offsetWidth,

0 commit comments

Comments
 (0)