I am somewhat new to JS, and I've run into an error I am unable to resolve while using Intersection Observer.
Here is the code I am attempting to use:
const header = document.querySelector("navBarContainer");
const imageHeader = document.querySelector("myImageHeader");
const imageHeaderOptions = {
rootMargin: "-50px 0px 0px 0px"
};
const imageHeaderObserver = new IntersectionObserver(function(
entries,
imageHeaderObserver
) {
entries.forEach(entry => {
if (!entry.isIntersecting) {
header.classList.add("scrolled");
} else {
header.classList.remove("scrolled");
}
});
},
imageHeaderOptions);
imageHeaderObserver.observe(imageHeader);