html Shopify无限滚动 Posted 2021-05-11
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html Shopify无限滚动相关的知识,希望对你有一定的参考价值。
var Scroll = (function($, doc, win) {
var options = {};
var inprog = false;
var currPos = 0;
var maxPos = 0;
function getNextPage() {
options.ajaxData['page'] = options.page;
options.page += 1;
return $.ajax(this.url, {
data: options.ajaxData
});
}
function loadMore() {
getNextPage().done(function(data) {
$(options.container).append(data);
inprog = false;
});
}
return function(data) {
options.page = data.page || 2;
options.offset = data.offset || 100;
options.container = data.container || '.scroll-container';
options.url = data.url;
options.ajaxData = data.ajaxData;
var $doc = $(doc);
var $win = $(win);
$doc.scroll(function(){
currPos = $doc.scrollTop()+$win.height();
maxPos = $doc.height()-options.offset;
if(currPos>=maxPos && inprog===false) {
inprog = true;
loadMore();
}
});
}
})($, document, window);
// Example usage
Scroll({
url: '/blogs/news',
ajaxData: { view: 'blog-ajax' },
offset: 500
});
<!--
a new template will need to be created for this file then this will
be what's called from the ajax by sending it with a property of
view:*template name*.
-->
{% layout none %}
{% paginate items by 5 %}
{% for item in items %}
<!-- item html -->
{% endfor %}
{% endpaginate %}
以上是关于html Shopify无限滚动的主要内容,如果未能解决你的问题,请参考以下文章
React Native Shopify StoreFront API GraphQL API 无限加载产品 fetchMore 错误
HTML5 无限循环滚动图片流
Java HTML 解析具有无限滚动的页面
html FacetWP无限滚动和加载
html Vue InstantSearch - 无限滚动示例
利用递归 实现UIScrollView无限滚动的效果