More actions
No edit summary |
No edit summary |
||
Line 45: | Line 45: | ||
} | } | ||
// Helper: Smooth scroll to heading with smart | // Helper: Smooth scroll to heading after expansion with smart delay | ||
function smoothScrollToHeading(heading) { | function smoothScrollToHeading(heading) { | ||
if (!heading) return; | if (!heading) return; | ||
heading.scrollIntoView({ behavior: 'smooth', block: 'start' }); | setTimeout(() => { | ||
heading.scrollIntoView({ behavior: 'smooth', block: 'start' }); | |||
setTimeout(() => { | |||
const offset = 60; // How much we want to adjust upward | |||
const maxScrollableUp = window.scrollY; // How much room we have to scroll upward | |||
if (maxScrollableUp > offset) { | |||
window.scrollBy(0, -offset); // Only scroll up if possible | |||
} else { | |||
window.scrollTo({ top: 0, behavior: 'smooth' }); // Scroll to top if near top | |||
} | |||
}, 300); // Wait for smooth scroll to finish before offset | |||
}, 300); // Wait for DOM reflow after expansion | |||
} | } | ||