diff --git a/js/app.js b/js/app.js index dbb1981..c9c55c0 100644 --- a/js/app.js +++ b/js/app.js @@ -262,7 +262,7 @@ }); const io = new IntersectionObserver((entries) => { entries.forEach((entry) => { - if (entry.intersectionRatio > 0) { + if (entry.isIntersecting) { entry.target.classList.add("active"); const blockId = entry.target.getAttribute("id"); const relatedChapterLink = document.querySelector(`a[href="#${blockId}"]`); @@ -270,6 +270,8 @@ } else { } }); + }, { + rootMargin: "-10% 0px -70% 0px" }); const questionsContainerBlocks = document.querySelectorAll(".questions-container-block"); const vocabulaireSummaryBlock = document.querySelector(".homegrade-blocks-vocabulaire-summary"); diff --git a/resources/js/single-conseil.js b/resources/js/single-conseil.js index f1e6250..86628c9 100644 --- a/resources/js/single-conseil.js +++ b/resources/js/single-conseil.js @@ -43,20 +43,25 @@ export default function singleConseil() { }); // Register IntersectionObserver - const io = new IntersectionObserver((entries) => { - entries.forEach((entry) => { - if (entry.intersectionRatio > 0) { - // Add 'active' class if observation target is inside viewport - entry.target.classList.add('active'); - const blockId = entry.target.getAttribute('id'); - const relatedChapterLink = document.querySelector(`a[href="#${blockId}"]`); - handleChapterIndicatorPosition(relatedChapterLink.offsetTop); - } else { - // Remove 'active' class otherwise - // entry.target.classList.remove('active'); - } - }); - }); + const io = new IntersectionObserver( + (entries) => { + entries.forEach((entry) => { + if (entry.isIntersecting) { + // Add 'active' class if observation target is inside viewport + entry.target.classList.add('active'); + const blockId = entry.target.getAttribute('id'); + const relatedChapterLink = document.querySelector(`a[href="#${blockId}"]`); + handleChapterIndicatorPosition(relatedChapterLink.offsetTop); + } else { + // Remove 'active' class otherwise + // entry.target.classList.remove('active'); + } + }); + }, + { + rootMargin: '-10% 0px -70% 0px', + } + ); const questionsContainerBlocks = document.querySelectorAll('.questions-container-block'); const vocabulaireSummaryBlock = document.querySelector('.homegrade-blocks-vocabulaire-summary'); const allBlocks = [...questionsContainerBlocks, vocabulaireSummaryBlock];