How to make product image change when mouse over in Shopify
You can add a hover effect to your product images on the home page and on collection pages. When a customer moves the cursor over a product image, the image will change to show either an alternate product image:
Follow the steps for the customization:
Step 1: Add CSS to your stylesheet
To add a hover effect, you will need to add some CSS code to your theme’s stylesheet:
- From your Shopify admin, go to Online Store > Themes.
- Find the theme you want to edit, and then click Actions > Edit code.
- In the Assets directory, click theme.css.liquid. If your theme doesn’t have a theme.css.liquid file, then click styles.css.liquid, or another file with a .css.liquid file extension.
- At the very bottom of the file, paste this code hosted on GitHub.
- Click Save.
Step 2: Edit the code for your product images
To edit the code for your product images:
- In the Snippets directory, click product-grid-item.liquid.If your theme doesn’t have a product-grid-item.liquid file, then look for one of the following:
- product-card.liquid
- product-card-grid.liquid
- product-loop.liquid
- Find the HTML img tag for your product images by searching for:1<img
The code for the tag varies theme to theme, but always starts with <img, and ends with either > or />. It might look similar to this:
1<img src="{{ featured.featured_image.src | img_url: '450x450' }}" alt="{{ featured.featured_image.alt | escape }}"> - On a new line above the img tag, paste the following code:1<div class="reveal">
On a new line below the img tag, paste the following code:
1</div>The result should look like this:
123<div class="reveal"><img src="{{ featured.featured_image.src | img_url: '450x450' }}" alt="{{ featured.featured_image.alt | escape }}"></div> - On a new line below the img tag and above the closing </div> tag, add the code that changes what is shown on hover. The code that you add will vary depending on whether you want to show an alternate product image, custom text, or a combination of the two.
Step 3: Show an alternate product image on hover
- On a new line below the img tag and above the closing </div> tag, paste the following code:1<img class="hidden" src="{{ product.images.last | img_url: '450x450' }}" alt="{{ product.images.last.alt | escape }}" />
Your code should look like this:
1234<div class="reveal"><img src="{{ featured.featured_image.src | img_url: '450x450' }}" alt="{{ featured.featured_image.alt | escape }}"><img class="hidden" src="{{ product.images.last | img_url: '450x450' }}" alt="{{ product.images.last.alt | escape }}" /></div> - Click Save.
Hi
can you give tutorials on cart drawer in shopify?
Hi
We’ve collected the Shopify apps help you create cart drawer in Shopify and list here: https://www.huratips.com/tech-tips/the-shopify-apps-help-you-create-cart-drawer-in-shopify.html.
If having time, I will write an article guide create the cart drawer on Shopify without app.
Cheers,
Hi, does this work with the Brooklyn theme? I have tried it multiple times with no luck
doesnt work in debut theme
I can’t get this to work in the DEBUT theme either ;(
Doesn’t work in Debut as of today for me.
Tried the same code method from elsewhere. Text just hovers over the image.
I simplified this for the Debut theme.
https://github.com/phillipkingston/Shopify—Change-Image-On-Hover
doesn’t work on the debut theme either, instead it displays a long photo with the two variant one on top of the other one
its working thank you
This is awesome. Thank you for sharing!
This doesn’t work for the Envy them.
If you consider yourself non-technical, there are Shopify apps for you https://www.huratips.com/tech-tips/5-cool-change-product-image-on-hover-apps-for-shopify.html
Thank you very much. Worked perfectly!