Skip to content

Instantly share code, notes, and snippets.

@dpw1
Last active March 4, 2024 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpw1/8369f676fda79f52d6c9f29ae7137e0d to your computer and use it in GitHub Desktop.
Save dpw1/8369f676fda79f52d6c9f29ae7137e0d to your computer and use it in GitHub Desktop.
Choose which image to show on hover (instead of the second one)
{% assign second_image_number = 3 %}
{% assign image_to_show = second_image_number | minus:1 %}
{% assign ezfy_image_on_hover = card_product.media[image_to_show] %}
<img
srcset="
{%- if ezfy_image_on_hover.width >= 165 -%}{{ ezfy_image_on_hover | image_url: width: 165 }} 165w,{%- endif -%}
{%- if ezfy_image_on_hover.width >= 360 -%}{{ ezfy_image_on_hover | image_url: width: 360 }} 360w,{%- endif -%}
{%- if ezfy_image_on_hover.width >= 533 -%}{{ ezfy_image_on_hover | image_url: width: 533 }} 533w,{%- endif -%}
{%- if ezfy_image_on_hover.width >= 720 -%}{{ ezfy_image_on_hover | image_url: width: 720 }} 720w,{%- endif -%}
{%- if ezfy_image_on_hover.width >= 940 -%}{{ ezfy_image_on_hover | image_url: width: 940 }} 940w,{%- endif -%}
{%- if ezfy_image_on_hover.width >= 1066 -%}{{ ezfy_image_on_hover | image_url: width: 1066 }} 1066w,{%- endif -%}
{{ ezfy_image_on_hover | image_url }} {{ ezfy_image_on_hover.width }}w
"
src="{{ ezfy_image_on_hover | image_url: width: 533 }}"
sizes="(min-width: {{ settings.page_width }}px) {{ settings.page_width | minus: 130 | divided_by: 4 }}px, (min-width: 990px) calc((100vw - 130px) / 4), (min-width: 750px) calc((100vw - 120px) / 3), calc((100vw - 35px) / 2)"
alt=""
class="motion-reduce"
loading="lazy"
width="{{ ezfy_image_on_hover.width }}"
height="{{ ezfy_image_on_hover.height }}"
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment