More actions
No edit summary |
No edit summary |
||
| Line 45: | Line 45: | ||
} | } | ||
// Helper: | // Helper: Proper scroll to real heading element, ignoring ghost anchors | ||
function smoothScrollToHeading(heading) { | function smoothScrollToHeading(heading) { | ||
if (!heading) return; | if (!heading) return; | ||
// If the heading has no visible size (hidden anchor), find the first real heading | |||
if (heading.offsetHeight === 0) { | |||
const nextHeading = heading.parentElement.querySelector('h1, h2, h3, h4, h5, h6'); | |||
if (nextHeading) { | |||
heading = nextHeading; | |||
} | |||
} | |||
setTimeout(() => { | setTimeout(() => { | ||
| Line 53: | Line 61: | ||
setTimeout(() => { | setTimeout(() => { | ||
const offset = 60; // | const offset = 60; // Adjust this offset if needed | ||
const maxScrollableUp = window.scrollY; | const maxScrollableUp = window.scrollY; | ||
if (maxScrollableUp > offset) { | if (maxScrollableUp > offset) { | ||
window.scrollBy(0, -offset); | window.scrollBy(0, -offset); | ||
} else { | } else { | ||
window.scrollTo({ top: 0, behavior: 'smooth' }); | window.scrollTo({ top: 0, behavior: 'smooth' }); | ||
} | } | ||
}, 300); | }, 300); | ||
}, | }, 100); // Minor wait to ensure layout stabilizes | ||
} | } | ||