简体   繁体   English

如何将无限滚动添加到 BigCommerce 类别页面

[英]How to add Infinite Scroll to BigCommerce Category page

I am trying to add infinite scroll to the category page on BigCommerce.我正在尝试向 BigCommerce 的类别页面添加无限滚动。 Infinite Scroll无限滚动

I have uploaded the JS script to the content file on webdav and inserted the HTML code on the category.html page but it won't work.我已将 JS 脚本上传到 webdav 上的内容文件,并在category.html页面上插入了 HTML 代码,但它不起作用。 I think because it's a partial page that gets injected into the base.html .我想是因为它是一个被注入base.html的部分页面。 I have added the script into that page to no avail.我已将脚本添加到该页面但无济于事。 I am not sure how to call the script with jQuery or JavaScript as shown in the instructions.我不确定如何按照说明中所示使用 jQuery 或 JavaScript 调用脚本。

Can anyone shed some light?任何人都可以阐明一下吗?

Try initializing Infinite Scroll on grid.html (or whichever template file creates the <ul> for the category products in your theme).尝试在 grid.html(或为主题中的类别产品创建<ul>任何模板文件)上初始化 Infinite Scroll。 Here's an example using the HTML initialization method, applied to the grid.html file from Cornerstone:下面是一个使用 HTML 初始化方法的示例,应用于 Cornerstone 的 grid.html 文件:

<ul class="productGrid" data-infinite-scroll='{ "path": ".pagination-link", "append": ".product", "history": false }'>
{{#each products}}
<li class="product">
    {{>components/products/card show_compare=../show_compare show_rating=../settings.show_product_rating theme_settings=../theme_settings customer=../customer}}
</li>
{{/each}}

Just be sure that you are referencing the Infinite Scroll .js files in the {{head}} section of base.html, either with the path to the file in WebDAV, or using the CDN link:请确保您在 base.html 的 {{head}} 部分中引用了 Infinite Scroll .js 文件,或者使用 WebDAV 中文件的路径,或者使用 CDN 链接:

<script src="https://unpkg.com/infinite-scroll@3/dist/infinite-scroll.pkgd.js"></script> 

Edit: Updating after a user reported that this is now duplicating the first page of category products.编辑:用户报告现在正在复制类别产品的第一页后更新。 New markup making path specific to Next link:特定于 Next 链接的新标记制作路径:

data-infinite-scroll='{ "path": ".pagination-item--next .pagination-link", "append": ".product", "history": false }'

Step by step information here .一步一步的信息在这里

There are two ways to install infinite scroll in your themes.有两种方法可以在您的主题中安装无限滚动。

  1. Directly, we can include infinite scroll using CDN URLs.直接,我们可以使用 CDN URL 包含无限滚动。 We need to add below the code inside the tag.我们需要在标签内的代码下方添加。

    <script src="https://unpkg.com/infinite-scroll@4/dist/infinite-scroll.pkgd.js"></script>

  2. NPM package to install infinite scroll.安装无限滚动的 NPM 包。

Install with npm:使用 npm 安装:

npm install infinite-scroll

Install with yarn:用纱线安装:

yarn add infinite-scroll

Notes: The direct method may affect some issues.注意:直接方法可能会影响一些问题。 Some browsers are not allowed to use separate network fetch calls.某些浏览器不允许使用单独的网络提取调用。 We prefer to use the NPM package method.我们更喜欢使用 NPM 打包方式。

Npm is the best way to use infinite scroll npm 是使用无限滚动的最佳方式

Install with npm:使用 npm 安装:

npm install infinite-scroll

Install with yarn:用纱线安装:

yarn add infinite-scroll

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM