Skip to content

Instantly share code, notes, and snippets.

@ashukasma
Created December 17, 2015 08:00
Show Gist options
  • Save ashukasma/c38e54ade11e0c976e43 to your computer and use it in GitHub Desktop.
Save ashukasma/c38e54ade11e0c976e43 to your computer and use it in GitHub Desktop.
Shopify image cross fading
.grid-link__image-centered{
display:block;
position:relative;
.original{
opacity:1;
transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-webkit-transition: opacity 1s ease-in-out;
}
.alternative{
transition: opacity 1s ease-in-out;
-moz-transition: opacity 1s ease-in-out;
-webkit-transition: opacity 1s ease-in-out;
position:absolute;
top:0px;
left:0px;
opacity:0;
left: 50%;
top: 50%;
/*
Nope =(
margin-left: -25%;
margin-top: -25%;
*/
/*
Yep!
*/
transform: translate(-50%, -50%);
}
&:hover{
.original{
opacity:0;
}
.alternative{
opacity:1;
}
}
}
<span class="grid-link__image-centered">
{% assign notused = true %}
{% for image in product.images %}
{% if notused and image.id != product.featured_image.id %}
<img src="{{ product.featured_image.src | img_url: 'large' }}" alt="{{ product.featured_image.alt | escape }}" class="original">
<img src="{{ image | img_url: image_size }}" alt="{{ image.alt | escape }}" class="alternative">
{% assign notused = false %}
{% endif %}
{% endfor %}
{% if notused %}
<img src="{{ product.featured_image.src | img_url: image_size }}" alt="{{ product.featured_image.alt | escape }}">
{% endif %}
</span>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment