I understand how to use Intersection Observer to check if an element has entered the viewport, such as the code below:
const el = document.querySelector('#el')
const observer = new window.IntersectionObserver(([entry]) => {
if (entry.isIntersecting) {
console.log('ENTER')
return
}
console.log('LEAVE')
}, {
root: null,
threshold: 0.1, // set offset 0.1 means trigger if atleast 10% of element in viewport
})
observer.observe(el);
Is it possible to detect if the element crossed the middle of the viewport('50vh' from the top)?
If so, could you please include a code example for clarity?