I' trying to make a menu that change color when the background has a specific class. I'm using Intersection Observers, but it doesn't work. Basically i want something like this: If(ONE of the elements are in view) { add a class to the menu } If(ALL of the elements out of view) { remove a class to the menu }
Check out this codepen: https://codepen.io/andreas-rasmussen/pen/oNZKJwm
Basically it's suppose to work like this header: https://www.eiffelcph.dk
const options = {
root: null,
rootMargin: "0px 0px 87% 0px",
threshold: 0
};
let callback = (entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
$(".logo").addClass("white");
} else {
$(".logo").removeClass("white");
}
});
};
let observer = new IntersectionObserver(callback, options);
document.querySelectorAll(".dark-menu").forEach((darkmenu) => {
observer.observe(darkmenu);
});