Improvement There is a great video, by Fireship, that shows a cleaner approach using IntersectionObserver. Check it out here: https://www.youtube.com/watch?v=T33NN_pPeNI