Andreik289
Andreik289
KPCKevin Powell - Community
Created by Andreik289 on 8/30/2023 in #front-end
IntersectionObserver for multiple targets
Ok but if I modify the function to get out from callback when at least one element is intersecting why it doesn't work? This should prevent the callback to bounce between multiple fires and show the button when at least one .intersect element is found but instead if a div occupy the entire viewport and the start and end of div is out of viewport, the interesect it's simply false. Am I right?
function observerCallback(entries, observer) {
var intersect = false;
for(entry of entries) {
if(entry.isIntersecting) {
intersect = true;
break;
}
};
if (intersect) {
target.classList.add('visible');
} else {
target.classList.remove('visible');
}
};
function observerCallback(entries, observer) {
var intersect = false;
for(entry of entries) {
if(entry.isIntersecting) {
intersect = true;
break;
}
};
if (intersect) {
target.classList.add('visible');
} else {
target.classList.remove('visible');
}
};
7 replies