Skip to content

Commit 6c02a59

Browse files
committed
added function for calculating the offset and fixed the offset of the calculation for the element
1 parent 9786823 commit 6c02a59

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

modules/mixins/utils.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ const getHash = () => {
2121

2222
const filterElementInContainer = (container) => (element) => container.contains ? container != element && container.contains(element) : !!(container.compareDocumentPosition(element) & 16)
2323

24+
const calculatingOffsetParent = (c, t) =>
25+
t.offsetParent.isEqualNode(c) ? t.offsetTop : t.offsetTop + calculatingOffsetParent(c, t.offsetParent);
26+
2427
const scrollOffset = (c, t) => c === document ?
25-
t.getBoundingClientRect().top + (window.scrollY || window.pageYOffset) : getComputedStyle(c).position !== "static" ? t.offsetTop : (t.getBoundingClientRect().top + c.scrollTop)
28+
t.getBoundingClientRect().top + (window.scrollY || window.pageYOffset) : getComputedStyle(c).position !== 'static' ? calculatingOffsetParent(c, t) : calculatingOffsetParent(c.offsetParent, t.offsetParent) - c.offsetTop;
2629

2730
export default {
2831
pushHash,
2932
getHash,
3033
filterElementInContainer,
3134
scrollOffset
32-
};
35+
};

0 commit comments

Comments
 (0)