Skip to content

Commit

Permalink
Apply header offset to on-this-page script
Browse files Browse the repository at this point in the history
  • Loading branch information
doup committed Dec 5, 2024
1 parent 289aea0 commit 4e48213
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion static/on-this-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ function otp_set_active(id_or_node){
});
}

let headerHeight = getComputedStyle(document.body).getPropertyValue(
"--header-height"
);

let otp_observer = new IntersectionObserver(
entries => {
entries.forEach(entry => {
Expand All @@ -43,7 +47,7 @@ let otp_observer = new IntersectionObserver(
otp_set_active(intersecting[0]);
}
}, {
rootMargin: "0px 0px 20% 0px",
rootMargin: `-${headerHeight} 0px 20% 0px`,
threshold: 1.0,
});

Expand Down

0 comments on commit 4e48213

Please sign in to comment.