🛠️ Infinite Scroll: Implementing the Infinite Scroll

Hey ,

I'm thrilled to help you learn JavaScript. Unfortunately, you've landed on a page where you cannot access with your current purchase.

Please upgrade (use this link) access this content.

I'm super eager to help you learn more!

🛠️ Infinite Scroll: Implementing the Infinite Scroll

Now’s the time! Finally, we are ready to implement the Infinite Scroll.

We want to load more content as users scroll down. Here, we can use loadMoreButton as a landmark. When loadMoreButton appears in view, we click it, so it loads the next set of content.

const observer = new IntersectionObserver(entries => {
  entries.forEach(entry => {
    if (entry.isIntersecting) {
      entry.target.click()
    }
  })
})

observer.observe(loadMoreButton)

And that’s it!