My problem is the following code is only properly working when scrolling up.
But when scrolling down it detects the last intersecting element instead of the top most / first.
const observer = new IntersectionObserver(entries => {
let first = null;
entries.forEach(entry => {
if (entry.isIntersecting) {
const target = entry.target;
if (target.matches('h2, h3, h4, h5, h6, p, ul')) {
first = target;
return;
}
}
});
tried as well with entry.boundingClientRect.top < 0
didn t work out…