Recently, working on one project, I had to create an infinite scroll on the news page, which is a view. There are several ways to make it work, but for me, the easiest one was using the Views Infinite Scroll module. I'll explain to you in this tutorial, step by step, how to accomplish this.
First, you have to download and install the Views Infinite Scroll module if you haven't already.
Then go to your View configuration page, and under the `Pager` section set the 'Use pager' option to Infinite Scroll. Then choose 'Automatically Load Content' and set the number of items that will be loaded. In my case it's 3, you can set it however you like. Just make sure that the 'More link' option is set to 'No'.
Clear your cache.
After you visit your View page, you can see already View infinity scroll working.
In case you wish loading animation to also appear, we'll have to make some custom changes in the template file of Views infinite scroll module views-infinite-scroll-pager.html.twig.
It's located in '/modules/views_infinite_scroll/templates'.
You can copy that file into templates folder of your custom theme, and add some changes, like these:
All I did was just adding one div with class name 'loading' to an image positioned in it. That image will be our loading animation.
Also, I made some customization in CSS, where I have positioned that loading animation centered in that div and set it to appear every time it`s needed.
After you have finished all these steps, clear again your cache and visit the page. You should see the expected result.