npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

baymax-shopify-product-swiper

v1.0.0

Published

shopify 幻灯片组件

Downloads

3

Readme

Shopify 产品页面幻灯片组件

安装

使用 yarn 或 npm 下载代码

yarn add baymax-shopify-product-swiper
npm install baymax-shopify-product-swiper

引入文件

将下方两个文件引入到 snippets 目录下

baymax-shopify-product-swiper\lib\snippets\ib-product-media-swiper.liquid
baymax-shopify-product-swiper\lib\snippets\ib-product-media-swiper-slide.liquid

将swiper 文件引入到 assets 目录下

baymax-shopify-product-swiper\lib\swiper\swiper-bundle.css
baymax-shopify-product-swiper\lib\swiper\swiper-bundle.min.js
baymax-shopify-product-swiper\lib\swiper\swiper-bundle.min.js.map

引入配置

将下方代码引入到 settings_schema.json 中

{
    "name": "杂货店",
    "settings":[
      {
        "type":"header",
        "content": "产品页面幻灯片"
      },
      {
        "type": "select",
        "id": "ib_product_swiper_effect",
        "label": "过渡效果",
        "default": "slide",
        "options": [
          {
            "label": "滑动",
            "value": "slide"
          },
          {
            "label": "淡化",
            "value": "fade"
          },
          {
            "label": "立方体",
            "value": "cube"
          },
          {
            "label": "翻页",
            "value": "coverflow"
          },
          {
            "label": "翻转",
            "value": "flip"
          }
        ]
      },
      {
        "type": "range",
        "id": "ib_product_swiper_speed",
        "label": "过渡时间",
        "unit": "ms",
        "min": 100,
        "max": 3000,
        "step": 50,
        "default": 300
      },
      {
        "type": "html",
        "id": "ib_product_media_swiper_left_svg",
        "label": "向左图标 SVG"
      },
      {
        "type": "html",
        "id": "ib_product_media_swiper_right_svg",
        "label": "向右图标 SVG"
      },
      {
        "type": "checkbox",
        "id": "ib_product_media_swiper_use_default_color",
        "label": "使用彩色 SVG",
        "default": false
      },
      {
        "type": "color",
        "id": "ib_product_media_swiper_btn_color",
        "label": "图标颜色",
        "default": "#ffffff"
      },
      {
        "type": "color",
        "id": "ib_product_media_swiper_btn_color_bg",
        "label": "切换背景颜色",
        "default": "#ffb303"
      },
      {
        "type": "color",
        "id": "ib_product_media_swiper_border_color",
        "label": "边框颜色",
        "default": "#ffb303"
      }
    ]
  }

引入 swiper 插件

  {{ 'swiper-bundle.min.css' | asset_url | stylesheet_tag }}
  <script src="{{ 'swiper-bundle.min.js' | asset_url }}"></script>

注意:本组件基于 swiper 和 jquery 请确保主题引入了这两个插件

实例化产品页面幻灯片组件

在 theme.liquid 底部(正上方) 引入下方代码

{% if request.page_type == 'product' %}
<script>
	$(document).ready(function () { productMediaSlide() });
</script>
{% end %}

使用

引入片段

在产品页面对应要显示幻灯片的位置引入 ib-proudct-media-swiper 片段

{% include 'ib-proudct-media-swiper' %}

幻灯片 与 产品选项 联动

在幻灯片组件 swiper 实例为 window.ptMedioSwiper,我们可以通过 ptMedioSwiper 来操控我们的幻灯片

这里我只讲切换幻灯片的方法使用,其他方法可以查看 swiper 官方文档

切换幻灯片的方法


ptMedioSwiper.slideTo(index)
// index 是幻灯片的索引,它比我们 shopify 的 media.position 小 1
// 所以 我们 可以在 变体的选项上绑定上medio.position数据, variant.featured_media.position
// 当产品选泽发生改变时我们可以获取所选变体对应的 medio.position 数据,然后通过slideTo方法切换幻灯片
ptMedioSwiper.slideTo(position - 1)