shopifyintermediatemit

Product Card — Image Swap

Product card that swaps to a second image on hover.

7.1k2.3k1.1k266

About this module

A Shopify product card that reveals a second product image on hover — a subtle, high-converting interaction for catalogs.

#shopify#product#card#image#hover

Source code

Installation

  1. 1

    Open Shopify Admin

    Go to Online Store → Themes.

  2. 2

    Edit code

    Click the ellipsis (⋯) next to your theme and choose Edit Code.

  3. 3

    Create the section

    In the Sections folder, click Add a new section, name it mh-product-card-swap, and replace the contents with the Liquid source below.

  4. 4

    Save

    Save the file. The section now appears in the Theme Customizer.

  5. 5

    Add it to the page

    Open the Theme Customizer, click Add section, search for it and add it where you like.

Usage

  1. 1

    Paste the section

    Create `mh-product-card-swap` under Sections and paste the source.

    {{ 'styles.css' | asset_url | stylesheet_tag }}
    <div class="mh-swap">
      <a href="{{ product.url }}" class="mh-swap-media">
        {% if product.featured_image %}
          <img class="mh-swap-primary" src="{{ product.featured_image | image_url: width: 700 }}" alt="{{ product.featured_image.alt | escape }}" width="700" height="700" loading="lazy" />
        {% endif %}
        {% if section.settings.enable_swap and product.images[1] != blank %}
          <img class="mh-swap-secondary" src="{{ product.images[1] | image_url: width: 700 }}" alt="{{ product.images[1].alt | escape }}" width="700" height="700" loading="lazy" />
        {% endif %}
      </a>
      <div class="mh-swap-body">
        <a href="{{ product.url }}" class="mh-swap-title">{{ product.title }}</a>
        {% if section.settings.show_price %}
          <span class="mh-swap-price">{{ product.price | money }}</span>
        {% endif %}
      </div>
    </div>
    
    {% schema %}
    {
      "name": "MH Product Card Swap",
      "tag": "div",
      "settings": [
        { "type": "checkbox", "id": "enable_swap", "label": "Enable image swap on hover", "default": true },
        { "type": "checkbox", "id": "show_price", "label": "Show price", "default": true }
      ],
      "presets": [{ "name": "MH Product Card Swap", "category": "ModuleHarbor" }]
    }
    {% endschema %}
  2. 2

    Configure in the customizer

    Adjust the settings that ship with the section schema.

Overview
Categorye commerce
Frameworkshopify
Difficultyintermediate
Licensemit
Versionv1.0.0
Features
  • Complete {% schema %} settings
  • Presets included
  • Theme-friendly CSS variables
Traits
  • ResponsiveYes
  • Dark modeYes
  • AccessibleYes
  • Production readyYes
Browser support
  • Chrome 90+
  • Firefox 90+
  • Safari 15+
  • Edge 90+

Related modules

Command Palette

Search modules and jump anywhere