【发布时间】:2014-12-17 16:22:29
【问题描述】:
这段代码在我的网站上创建了无限滚动效果,它可以完美运行,但只能在最新版本的 Chrome 中运行。 Safari、FF 和 IE 不会初始化 ajax 调用,而是使用作为加载更多按钮的回退。
虽然它不起作用,但我创建了一个 jsFiddle,它代表我在 Shopify 集合页面中使用的标记,希望能让您更好地了解我的设置:http://jsfiddle.net/qpka6pyv/1/ 我做错了什么吗?
仅供参考,我正在使用 doTimeout plugin 来创建延迟(并非完全必要),并且我在名为“.st-content”的可滚动 div 中附加和加载更多项目,而不是 html 或正文。因此,当您滚动到“.st-content”的底部时,加载下一个 X 数量的产品。目前这仅适用于 Chrome。
这是 jQuery:
function ScrollExecute() {
if($(document).height() - 350 < ($(document).scrollTop() + $(window).height())) {
scrollNode = $('.scrollnode #more').last();
scrollURL = $('.scrollnode #more p a').last().attr("href");
if(scrollNode.length > 0 && scrollNode.css('display') != 'none') {
$.ajax({
type: 'GET',
url: scrollURL,
beforeSend: function() {
scrollNode.clone().empty().insertAfter(scrollNode).append('<img src=\"{{ "loading.gif" | asset_url }}\" />');
scrollNode.hide();
},
success: function(data) {
// remove loading feedback
scrollNode.next().remove();
var filteredData = $(data).find(".scrollnode");
filteredData.insertBefore( $("#product-list-foot") );
},
dataType: "html"
});
}
}
}
$(document).ready(function () {
$('.st-content').scroll(function(){
$.doTimeout( 'scroll', 100, ScrollExecute);
});
});
作为参考,我从这篇博客文章中获得了代码:http://www.davecap.com/post/9675189741/infinite-scroll-for-shopify-collections
【问题讨论】:
-
您是否调试并查看未正确调用的内容? console.log 是你的朋友。
-
我在任何浏览器中都没有收到控制台错误。
-
那么您是否添加了控制台行以查看是否触发了滚动...之后添加控制台行以查看为什么 if 语句不正确。
标签: javascript jquery html google-chrome infinite-scroll