Skip to content

Commit

Permalink
fix: toc
Browse files Browse the repository at this point in the history
  • Loading branch information
Jazee6 committed Dec 28, 2024
1 parent 2304af5 commit 088577d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/pages/posts/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const haveToc = headings.some(heading => heading.depth === 2 || heading.depth ==
const links = document.querySelectorAll('.menu-item');
const handler = debounce(() => {
const scrollY = window.scrollY;
if (scrollY < 80) {
if (scrollY < 84) {
links.forEach(link => link.classList.remove('bg-hover'));
links[0].classList.add('bg-hover');
history.replaceState(null, '', window.location.pathname);
Expand All @@ -84,7 +84,7 @@ const haveToc = headings.some(heading => heading.depth === 2 || heading.depth ==
const href = link.getAttribute('href') as string;
const target = document.querySelector(`[id="${href.slice(1)}"]`);
if (target) {
const offsetTop = target.getBoundingClientRect().top + scrollY - 80
const offsetTop = target.getBoundingClientRect().top + scrollY - 84
if (scrollY >= offsetTop) {
links.forEach(link => link.classList.remove('bg-hover'));
link.classList.add('bg-hover');
Expand Down

0 comments on commit 088577d

Please sign in to comment.