From 017555b92e6676879ec251a69e4c896a9162a7be Mon Sep 17 00:00:00 2001 From: Nonimart Date: Thu, 21 Aug 2025 14:51:42 +0200 Subject: [PATCH] FEATURE Handling an offset when scrolling to anchor to improve readability --- resources/js/singles/sommaire.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/resources/js/singles/sommaire.ts b/resources/js/singles/sommaire.ts index 9b8bb13..1345521 100644 --- a/resources/js/singles/sommaire.ts +++ b/resources/js/singles/sommaire.ts @@ -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