diff --git a/resources/js/single-conseil.js b/resources/js/single-conseil.js index 9d0ddd5..3f46065 100644 --- a/resources/js/single-conseil.js +++ b/resources/js/single-conseil.js @@ -16,9 +16,12 @@ export default function singleConseil() { }); targetBlock.focus({ preventScroll: true }); } - function handleChapterIndicatorPosition(targetPosition) { + function handleChapterIndicatorPosition(targetLink) { + const targetPosition = targetLink.offsetTop; + const targetHeight = targetLink.offsetHeight; let chapterIndicator = document.querySelector('.chapter_index__position-indicator'); chapterIndicator.style.top = targetPosition + 'px'; + chapterIndicator.style.height = targetHeight + 'px'; } let chapterLinks = document.querySelectorAll('.chapter_index__link'); @@ -40,9 +43,9 @@ export default function singleConseil() { if (entry.isIntersecting) { // Add 'active' class if observation target is inside viewport + handleChapterIndicatorPosition(relatedChapterLink); entry.target.classList.add('active'); relatedChapterLink.classList.add('active'); - handleChapterIndicatorPosition(relatedChapterLink.offsetTop); } else { // Remove 'active' class otherwise // entry.target.classList.remove('active');