We are looking to fire a JS event each time the top of the users browser passes a repeating div. For example.
<div class="refresh"></div>
If the above div was repeated multiple times on a page, we want to fire a specific event each time it is scrolled past (However, once it goes out of view on the top of the page rather than when it comes into view).
I have tried it but I can only get it to fire once rather than look for multiple divs.
2
Answers
this seems to work, there is probably a better way to do it.
Use IntersectionObserver judgment:
https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver
And if you use IntersectionObserver, you need to consider browser compatibility.