refining intersection observer position for chapterIndexIndicator
This commit is contained in:
parent
d90462e64b
commit
6e8dacf4ff
|
|
@ -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");
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user