【发布时间】:2018-03-26 07:29:37
【问题描述】:
我有一个网站,其中显示房地产搜索结果就像使用 <div>s 一样,默认情况下只显示 6 个和“加载更多”按钮。当用户点击加载更多按钮时,显示更多帖子等。如何完成:divs 默认隐藏(display: none;),然后将.show 类添加到接下来的 9 个项目中。
a("span.more-search-items").on("click", function(t) {
t.preventDefault();
var e = a(this).parents(".property-search");
e.find(".prop").not(".show").slice(0, 9).each(function() {
var t = a(this).attr("data-img");
a(this).css("background-image", "url(" + t + ")"), a(this).find(".main-image").attr("src", t), a(this).addClass("show")
}), 0 == e.find(".prop").not(".show").length && a("span.more-search-items").hide();
e.find(".prop.show").length
当用户转到单个属性然后点击返回浏览器按钮时,它会再次显示前 6 个项目。我尝试在那里实现history.pushState() 方法,其中每个“加载更多”按钮单击的 URL 都会发生变化:
var href = window.location.href.replace(window.location.hash, '');
var currentPage = location.hash.replace("#","");
history.pushState(null, null, href + "#" + (+currentPage + 1));
网址发生了变化,但故事仍然相同 - 当用户返回历史记录时,仅显示前 6 个结果。在这种情况下我能做些什么吗?
【问题讨论】:
-
所以你加载所有的 div 并使用
Load more来显示它们? -
是的,然后只延迟加载图像。
标签: javascript jquery browser-history