Created
June 14, 2025 00:59
-
-
Save saadsaif97/a824966a52d0cf1f5b85b525080c9bac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="variant-swatches"> | |
| {%- for variant in card_product.variants -%} | |
| <span | |
| class="variant-swatch" | |
| style="background-image: url({{ variant.featured_image | image_url: width: 200 }});" | |
| data-variant-image="{{ variant.featured_image | image_url: width: 500 }}" | |
| title="{{ variant.title }}"> | |
| </span> | |
| {%- endfor -%} | |
| </div> |
Author
Author
this script updates the swatch images, you can add at the bottom of theme.liquid
<script>
function updateSwatchImage() {
document.querySelectorAll(".variant-swatch").forEach(swatch => {
swatch.addEventListener("mouseover", () => {
let newImage = swatch.dataset.variantImage;
let image = swatch.closest(".product-card-wrapper")
.querySelector(".card__media img");
image.removeAttribute("srcset");
image.setAttribute("src", newImage);
})
})
}
document.addEventListener("CollectionGrid:updated", () => {
updateSwatchImage();
console.log("CollectionGrid:updated")
})
updateSwatchImage()
</script>
Author
in facets.js you need to dispatch this event in the funciton renderProductGridContainer
document.dispatchEvent(new CustomEvent("CollectionGrid:updated"))
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
you need to add the following css in the
component-card.css