Skip to content

Commit

Permalink
Update calculation of element offsets (#1739)
Browse files Browse the repository at this point in the history
* Update element offset computation

Updated logic for computing element top and left offset to use document.documentElement and window, from document.body since document.body always returns 0

Signed-off-by: AngeloKarugo <52207274+AngeloKarugo@users.noreply.github.com>

* made new element offset calculation method, changed scrollspy offset method

---------

Signed-off-by: AngeloKarugo <52207274+AngeloKarugo@users.noreply.github.com>
  • Loading branch information
AngeloKarugo committed Jul 24, 2023
1 parent 1b82062 commit fbd0564
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/js/dom/manipulator.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,27 @@ const Manipulator = {
hasClass(element, className) {
return element.classList.contains(className);
},

maxOffset(element) {
const rect = element.getBoundingClientRect();

return {
top:
rect.top +
Math.max(
document.body.scrollTop,
document.documentElement.scrollTop,
window.scrollY
),
left:
rect.left +
Math.max(
document.body.scrollLeft,
document.documentElement.scrollLeft,
window.scrollX
),
};
},
};

function _classNameOrListToArray(classNameOrList) {
Expand Down
2 changes: 1 addition & 1 deletion src/js/navigation/scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ const SELECTOR_LINK_ITEMS = `${SELECTOR_NAV_LINKS}, ${SELECTOR_LIST_ITEMS}, ${SE
const SELECTOR_DROPDOWN = "[data-te-dropdown-ref]";
const SELECTOR_DROPDOWN_TOGGLE = "[data-te-dropdown-toggle-ref]";

const METHOD_OFFSET = "offset";
const METHOD_OFFSET = "maxOffset";
const METHOD_POSITION = "position";

/*
Expand Down

0 comments on commit fbd0564

Please sign in to comment.