How to get always the first intersecting observer element when scrolling down?

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…

Ok is not working because i have paragraphs and ul too but I need to know how much time is spent on them as well …

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.