无限滚动-在后台自动加载下一个特定数量的帖子
Infinite Scroll - auto load next certain number of posts in background
我正在开发一个使用无限滚动的wordpress网站。它运行良好。但我需要做一些修改,以明显更快地加载。当网站完全加载时,我想再加载几个帖子,以便在后台自动加载(用户不知道加载了更多内容)。当他们到达页面底部(或单击加载更多帖子按钮)时,它会显示那些预先加载的帖子,然后系统再次开始在后台加载更多帖子,以此类推。通过这种方式,用户每次到达页面底部时都会看到快速的内容加载。
你知道如何做到这一点吗?
注意:不确定文档的html
结构、css
、现有js
,不会在原始帖子中出现html
。
下面的html
改编自《没有外部内容的无限卷轴》,也许也有类似的问题?
试试这个(图案)
html
<!-- Visible to users -->
<article>Pretend this is a preview (1) for an article on a blog</article>
<article>Pretend this is a preview (2) for an article on a blog</article>
<article>Pretend this is a preview (3) for an article on a blog</article>
<!-- End of Page -->
<!-- Infinite Scroll Load (Was Hidden Now Visible) -->
<article>Pretend this is a preview (4) for an article on a blog</article>
<article>Pretend this is a preview (5) for an article on a blog</article>
<article>Pretend this is a preview (6) for an article on a blog</article>
<button id="articles">Click to view more articles</button>
<!-- End of Page -->
js(更新)
$(function () {
$("body").css("height", $(document).height() + 1)
// `.load()` additional articles
.find("article").each(function (i, el) {
$(el).not(":nth-last-of-type(n+4)").hide()
.filter(":nth-of-type(4)").on("click.y", function () {
$("body").animate({
scrollTop: "0px"
}, 1000)
});
});
$(document).on("scroll.article", {
"scrolled": false
}, function (e) {
if (!e.data.scrolled) {
var el = $("article:nth-of-type(n+4)");
$(el).show(1000);
e.data.scrolled = true;
};
if (e.data.scrolled) {
$(el).on("click", function (e) {
$(e.target).hide(1000);
});
};
if ($("article:nth-of-type(n+4)").css("display") === "none") {
e.data.scrolled = false;
};
return false
});
$("#articles").on("click", $(document), function (e) {
// `.load()` additional articles
$(e.target).trigger("scroll.article").scroll()
})
});
jsfiddlehttp://jsfiddle.net/guest271314/bG5N8/
相关文章:
- 第二组标签及其内容赢得'默认情况下t加载
- 在没有POST的情况下重新加载父窗口
- 在混合基本 URL 下动态加载 require.js 模块
- 如何在我的情况下创建加载脚本
- 是否可以在不将其添加到DOM的情况下预加载和缓存视频文件
- 当一个ajax是SUCCESS时,下一个加载
- 用一个加载项绘制图像阵列
- HTML页面在使用JavaScript的条件下重新加载
- 如何在不重置防篡改的脚本的情况下重新加载页面
- 如何在不干扰页面其余部分的情况下预加载图像's的东西
- 在 Django 中向下滚动加载数据
- 为什么串联的 RequireJS AMD 模块需要一个加载器
- KendoUi 列表视图“按下以加载更多”无法使用 MVVM 样式
- 在不发送帖子数据的情况下重新加载带有 #anchor 的页面
- 在不刷新 HTML 的情况下重新加载 JavaScript 文件
- 如何在离线模式下不加载谷歌图表
- 如何在不刷新的情况下重新加载号码
- 在不刷新的情况下重新加载时从 url 获取 php 变量
- 按下按钮,有一个加载弹出窗口,然后更改弹出文本
- Mongoose:在一个集合下动态加载不同的模式