确保您从 http// 地址运行页面,如果您从本地文件运行它,无限滚动将不起作用。我使用 node、npm 和 express 设置了一个本地环境,看起来像这样......
var express = require("express");
var PORT = 8080;
var app = express();
app.use(express.static("public"))
app.listen(PORT, function(){
console.log("App listening on PORT: " + PORT)
})
所以我的文件夹结构看起来像这样
.
├── node_modules
│<br>
├── public
│ |── page1.html
│ |__ page2.html
│ |__ page3.html
│
├── server.js
│
您要加载的每个部分都必须是其自己的 .html 文件。所以正文 page1.html 看起来像这样。我更改了您的代码以在容器内包含一个 div 来保存帖子,并将 data-infinite-scroll 属性赋予 div .posts-feed。然后我移动了这个
<div class="scroller-status">
<div class="loader-ellips infinite-scroll-request">
<span class="loader-ellips__dot"></span>
<span class="loader-ellips__dot"></span>
<span class="loader-ellips__dot"></span>
<span class="loader-ellips__dot"></span>
</div>
<p class="scroller-status__message infinite-scroll-last">End of content</p>
<p class="scroller-status__message infinite-scroll-error">No more pages to load</p>
</div>
<p class="pagination">
<a class="pagination__next" href="page2.html">Next page</a>
</p>
在容器内。
<body>
<div class="main">
<div class="container" >
<div class ="posts-feed" data-infinite-scroll='{ "path": ".pagination__next", "append": ".post", "status": ".scroller-status", "hideNav": ".pagination"}' >
<article class="post">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In hendrerit in sem eu elementum. Nam sagittis eleifend aliquam. Cras viverra, sapien vel auctor viverra, augue leo commodo ipsum, id euismod elit nisl id felis. Integer vitae mauris est. Cras vitae varius tortor. Nullam tristique ullamcorper imperdiet. Suspendisse potenti. Donec in elit felis. Donec eget nunc porttitor, lobortis lectus id, sagittis urna. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Etiam vitae ornare purus. Sed augue purus, cursus in malesuada non, interdum molestie massa. In interdum nisi at purus gravida rutrum. Praesent finibus lacus ac imperdiet tincidunt.</p>
<p><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br></p>
</article>
</div>
<div class="scroller-status">
<div class="loader-ellips infinite-scroll-request">
<span class="loader-ellips__dot"></span>
<span class="loader-ellips__dot"></span>
<span class="loader-ellips__dot"></span>
<span class="loader-ellips__dot"></span>
</div>
<p class="scroller-status__message infinite-scroll-last">End of content</p>
<p class="scroller-status__message infinite-scroll-error">No more pages to load</p>
</div>
<p class="pagination">
<a class="pagination__next" href="page2.html">Next page</a>
</p>
</div>
</div>
</body>
注意最后有一个看起来像这样的片段
<p class="pagination">
<a class="pagination__next" href="page2.html">Next page</a>
</p>
这告诉无限滚动在 href 中下一步要加载什么。然后,这里将从一个名为 page2.html 的单独文件中加载内容
然后应该阅读同一部分的 page2.html
<p class="pagination">
<a class="pagination__next" href="page3.html">Next page</a>
</p>
以便加载 page3.html 内容。