FEATURE Handling an offset when scrolling to anchor to improve readability
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Nonimart 2025-08-21 14:51:42 +02:00
parent 1be03a7641
commit 017555b92e

View File

@ -2,7 +2,13 @@ export function handleSmoothScrollToTitle(targetId: string): void {
const targetElement = document.querySelector(`#${targetId}`);
if (!targetElement) return;
targetElement.scrollIntoView({ behavior: 'smooth' });
const elementRect = targetElement.getBoundingClientRect();
const offset = 30; // 10px offset from top
window.scrollTo({
top: window.pageYOffset + elementRect.top - offset,
behavior: 'smooth',
});
}
// Fonction équivalente à sanitize_title() de WordPress