17 lines
523 B
TypeScript
17 lines
523 B
TypeScript
export function handleSmoothScrollToTitle(): void {
|
|
const sommaireTitles: NodeListOf<Element> = document.querySelectorAll('.sommaire-index li a');
|
|
for (const title of sommaireTitles) {
|
|
title.addEventListener('click', (e) => {
|
|
e.preventDefault();
|
|
|
|
const target = title.getAttribute('href');
|
|
if (!target) return;
|
|
|
|
const targetElement = document.querySelector(target);
|
|
if (!targetElement) return;
|
|
|
|
targetElement.scrollIntoView({ behavior: 'smooth' });
|
|
});
|
|
}
|
|
}
|