Skip to content

Instantly share code, notes, and snippets.

@vosters
Created January 3, 2018 03:40
Show Gist options
  • Save vosters/0d40ad50d9c59dfe9f1d3883323144e3 to your computer and use it in GitHub Desktop.
Save vosters/0d40ad50d9c59dfe9f1d3883323144e3 to your computer and use it in GitHub Desktop.
Display 2nd product image on hover within Shopify collection loop
<a href="{{ product.url | within: collection }}" class="grid__image" {% if template == 'product' %}onclick="ga('send', 'event', 'Related Products', 'Clicked Related Product - {{ product.type }}', '{{ product.title }}');"{% elsif template == 'index' %}onclick="ga('send', 'event', 'Homepage Products', 'Clicked Best Sellers - {{ product.title }}');"{% endif %}>
{% if product.images.size > 1 %}
<img src="{{ product.images[0] | product_img_url: 'large' }}" alt="{{ product.title | escape }}" />
<img src="{{ product.images[1] | product_img_url: 'large' }}" alt="{{ product.title | escape }}" style="display:none" />
{% else %}
<img src="{{ product.featured_image.src | img_url: 'large' }}" alt="{{ product.featured_image.alt | escape }}">
{% endif %}
</a>
.product-grid a:hover img:last-child {
display: block !important;
}
.product-grid a:hover img:first-child {
display: none;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment