toc
All checks were successful
Build & Deploy KLZ Cables / build-and-deploy (push) Successful in 3m39s
All checks were successful
Build & Deploy KLZ Cables / build-and-deploy (push) Successful in 3m39s
This commit is contained in:
@@ -19,7 +19,7 @@ export default function TableOfContents({ headings, locale }: TableOfContentsPro
|
||||
|
||||
useEffect(() => {
|
||||
const observerOptions = {
|
||||
rootMargin: '-100px 0% -80% 0%',
|
||||
rootMargin: '-10% 0% -70% 0%',
|
||||
threshold: 0
|
||||
};
|
||||
|
||||
@@ -31,12 +31,18 @@ export default function TableOfContents({ headings, locale }: TableOfContentsPro
|
||||
});
|
||||
}, observerOptions);
|
||||
|
||||
const elements = headings.map((h) => document.getElementById(h.id));
|
||||
elements.forEach((el) => {
|
||||
if (el) observer.observe(el);
|
||||
});
|
||||
// Use a small delay to ensure MDX content is rendered and IDs are present
|
||||
const timer = setTimeout(() => {
|
||||
const elements = headings.map((h) => document.getElementById(h.id));
|
||||
elements.forEach((el) => {
|
||||
if (el) observer.observe(el);
|
||||
});
|
||||
}, 500);
|
||||
|
||||
return () => observer.disconnect();
|
||||
return () => {
|
||||
clearTimeout(timer);
|
||||
observer.disconnect();
|
||||
};
|
||||
}, [headings]);
|
||||
|
||||
if (headings.length === 0) return null;
|
||||
|
||||
Reference in New Issue
Block a user