In the above code, we have a div with id “infinite-container” which will hold all the content and an div with id “infinite-indicator” which when visible means that the user has scrolled to the bottom of the page.

Javascript

First, we create an instance of the intersection observer

// create an intersection observer, it calls the loadMore function when the intersection of the element changesconst observer = new IntersectionObserver(loadMore);

Next we create references to the div elements

// element to detect end of pagevar indicator = document.querySelector('#infinite-indicator');