This might be a perfect case to use the new [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API). Do you have any ideas on this?