I've been looking at IntersectionObserver for detecting when en element is visible to the user by checking if it is inside the viewport. However, if another element covers the "target" element, it appears we can only detect this if we know which elements to watch specifically, as the observer always takes a target and a root to compare against:
function createObserver() {
var options = {
root: document.querySelector('#container'),
threshold: 0
};
var observer = new IntersectionObserver(callback, options);
observer.observe(document.querySelector('#box'));
}
What I need to do is specify a target to watch and then detect when any other element covers it, which seems to not be possible using IntersectionObserver. Thanks to anyone who can help!