- Use the alt text to associate the additional images - besides the variant image - to the option value. Example: say you have 3 images that show the Blue variants, then a) associate the first image as variant image to all Blue variants, and b) set the alt text of the 2 additional images to 'Blue'.
- Copy+paste the code found in the product.liquid snippet below at the bottom of your product.liquid template.
Only the images associated to the currently selected variant are shown. Other images are hidden.
- On page load, only the images associated to the selected variant will be shown.
- When a new variant is selected, only the images associated to that new variant will be shown.
- The wrapper of the image, if one is used, is hidden, so there will be no left-over border shown on the page when an image is hidden.
jQuery 1.7 or later.
Hi Caroline,
Thanks for this code, it works great, however when this code loads sometimes it doesn't layout the thumbnails correctly, and instead stacks them leaving loads of spare whitespace. Seems this is due to the thumbnails i nthe product pages being spread over multiple lines
Blue shoes stack fine: https://i.imgur.com/eszIPVJ.png
Red shoes do not: https://i.imgur.com/S1gCoaZ.png
Looking into it, using .detach() instead of .hide() fixes the issue but then I'm unsure where to .append() again.