A few hours trying to implement Infinite Scroll in the blog. The goal is simple, the main page is too long, I want it to load gradually. The authors of the plugin have a perfectly working example, however, no matter what I do, in my case, the plugin doesn’t work properly. I guess I'm missing something.
If I understood correctly, then the plugin works like this: we create a common div and articles inside it. When entering a page, a person sees the first article, when he scrolls down to the next article, the page is enlarged and 2 article is already displayed, and so on. It seems to be what I am doing.
I tried to attach it through the link
<script src = "https://unpkg.com/infinite-scroll@3/dist/infinite-scroll.pkgd.min.js"> </ script>
Tried to upload file to server
<script src = "js/infinite-scroll.pkgd.min.js"> </script>
I tried to make the elements themselves through jQuery, JavaScript and just html, as suggested in the documentation, but all is unsuccessful.
This is a link to a very simple page of the site where I tried to implement it: https://dinarkino.ru/new. At the moment, all paragraphs are loaded at once, although each of them is wrapped in a separate
<article class = "post"> ... </ article>
I'll be very thankful for help!
Make sure you are running the page from http// address, infinite scroll will not work if you are running it from you local files. I set up a local environment using node, npm and express that looks like this ...
So my folder structure looks like this
. ├── node_modules │├── public │ |── page1.html │ |__ page2.html │ |__ page3.html │ ├── server.js │
Each section you want to load has to be its own .html file. So the body page1.html would look like this. I changed your code to include a div inside of the container to hold the posts and gave the data-infinite-scroll attribute to the div .posts-feed. Then I moved this
To be inside of container.
Notice how at the end there is a piece that looks like this
This is telling infinite scroll what to load next in href. This here will then load the contents from a separate file called page2.html
Then one page2.html that same section should read
so that page3.html contents are loaded.