Comience su viaje transfronterizo
Póngase en contacto con nosotros

Servicio de atención al cliente

Atención al cliente

Diseñador (creación de prototipos Figma)

Agrupación de Imágenes de Variantes de Productos Shopify

1、进入代码后台,在snippets里面找到product-media.liquid

添加代码:

{% if current_variant_color == media.alt or media.alt == ‘all’ %}
data-matched
{% endif %}

2、在assets里找到global.js

添加代码:

updateMediaBasedOnVariant() {

    const mediaGallery = document.getElementById(

      `MediaGallery-${this.dataset.section}`

    );

    const options = this.currentVariant.options.map((option) =>

      option.toLowerCase()

    );

    const mediaWrapper = Array.from(

      mediaGallery.querySelectorAll(“.product__media-item”)

    );

    const mediaThumbnailWrapper = mediaGallery.querySelectorAll(

      “.thumbnail-list__item”

    );

    const mediaModal = document.querySelectorAll(

      “.product-media-modal__content img”

    );

    // Set the thumbnail display by default

    mediaThumbnailWrapper.forEach((media) => {

      media.removeAttribute(‘data-matched’);

    });

    // Set the media modal display by default

    mediaModal.forEach((media) => {

      media.removeAttribute(‘data-matched’);

    });

    const matchesMedia = mediaWrapper.filter((media) => {

      media.removeAttribute(‘data-matched’);

      const alt = media.getAttribute(“data-media-alt”);

      const isMatch = alt === “all” || this.currentVariant.options[0] === alt;

      if (isMatch) {

        const mediaId = media.getAttribute(“data-media-id”);

        const id = mediaId.split(“-“).pop();

        media.setAttribute(“data-matched”, true);

        const thumbnail = mediaGallery.querySelector(

          `[data-target=”${mediaId}”]`

        );

        thumbnail && (thumbnail.style.display = “block”);

        thumbnail && thumbnail.setAttribute(“data-matched”, true);

        const modal = document.querySelector(

          `.product-media-modal__content img[data-media-id=”${id}”]`

        );

        modal && (modal.setAttribute(“data-matched”, true));

      }

      return isMatch;

    });

    customElements.whenDefined(“media-gallery”).then(() => {

      mediaGallery.setActiveMedia(

        matchesMedia[0].getAttribute(“data-media-id”),

        true

      );

    });

    // Reset the slider

    customElements.whenDefined(“slider-component”).then(() => {

      const sliders = mediaGallery.querySelectorAll(“slider-component”);

      sliders.forEach((slider) => {

        slider.resetPages();

      });

    });

  }

3、在assets里面找到section-main-product.css

代码1:

.product–thumbnail_slider .product__media-item:not([data-matched]) {
display: none !important;
}

代码2:

.thumbnail-list.slider–tablet-up .thumbnail-list__item.slider__slide:not([data-matched]) {
display: none !important;
}

.product-media-modal__content>img:not([data-matched]) {
display: none !important;
}