Relative Content

Tag Archive for javascriptintersection-observer

Adding active class to in-page nav using IntersectionObserver not working on tall elements

I am building a sidebar nav for a page with a lot of content in it, which scrolls to the associated section when clicked. I would like to also add a class to the currently visible section as you scroll down the page using IntersectionObserver. I have it partially working, but only when the element in question is short enough to fit entirely within the currently viewed portion of the page. If the element is taller than the page, it never triggers the intersecting. I have tried playing around with the rootMargin and threshold values but I am at a loss.

ClearTimeout through intersectionObserver

I have the following code which loads the next project in portfolio based on an intersectionObserver result being true. If however the user scrolls out so that intersectionObserver returns false I want to stop the redirection. This is not happeneing and the page simply reloads after 5 seconds.