carhop__dynamiques-theme__P.../resources/js/singles/sommaire.ts
Nonimart 71ee6d1bb6
Some checks failed
continuous-integration/drone/push Build is failing
REFACTOR optimizing injecting id to h2 by injecting in php instead of javascript
2025-08-21 15:05:57 +02:00

13 lines
390 B
TypeScript

export function handleSmoothScrollToTitle(targetId: string): void {
const targetElement = document.querySelector(`#${targetId}`);
if (!targetElement) return;
const elementRect = targetElement.getBoundingClientRect();
const offset = 30; // 10px offset from top
window.scrollTo({
top: window.pageYOffset + elementRect.top - offset,
behavior: 'smooth',
});
}