REFACTOR Fixing duplicate handleSmoothScrollToTitle function
This commit is contained in:
parent
4e66d244ee
commit
6d12445569
|
|
@ -69,12 +69,6 @@ function observeSommaireLinks(): void {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleSmoothScrollToTitle(targetId: string): void {
|
|
||||||
const targetElement = document.querySelector(`#${targetId}`);
|
|
||||||
if (!targetElement) return;
|
|
||||||
|
|
||||||
targetElement.scrollIntoView({ behavior: 'smooth' });
|
|
||||||
}
|
|
||||||
function toggleActiveChapterLinkInIndexPanel(targetId: string): void {
|
function toggleActiveChapterLinkInIndexPanel(targetId: string): void {
|
||||||
const sommaireLinks: NodeListOf<Element> = document.querySelectorAll('.sommaire-index li a');
|
const sommaireLinks: NodeListOf<Element> = document.querySelectorAll('.sommaire-index li a');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,6 @@
|
||||||
export function handleSmoothScrollToTitle(): void {
|
export function handleSmoothScrollToTitle(targetId: string): void {
|
||||||
const sommaireTitles: NodeListOf<Element> = document.querySelectorAll('.sommaire-index li a');
|
const targetElement = document.querySelector(`#${targetId}`);
|
||||||
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;
|
if (!targetElement) return;
|
||||||
|
|
||||||
targetElement.scrollIntoView({ behavior: 'smooth' });
|
targetElement.scrollIntoView({ behavior: 'smooth' });
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user