我试图在我的收藏页上的悬停上显示不同的产品图片。 Shopify提供了以下文章:https://help.shopify.com/en/themes/customization/collections/add-hover-effect-to-product-images
以下是product-grid-item.liquid页面上的代码:
<div class="reveal">
<img class="grid-product__image" src="{{ image.src | img_url: '1024x' }}" alt="{{ image.alt | escape }}">
<img class="hidden" src="{{ product.images.last | img_url: '1024x' }}" alt="{{ product.images.last.alt | escape }}" />
</div>
以下是添加到theme.scsss.liquid的代码:
/* ===============================================
// Reveal module
// =============================================== */
.reveal .hidden { display: block !important; visibility: visible !important;}
.product:hover .reveal img { opacity: 1; }
.reveal { position: relative; }
.reveal .hidden {
position: absolute;
z-index: -1;
top: 0;
width: 100%;
height: 100%;
opacity: 0;
-webkit-transition: opacity 0.3s ease-in-out;
-moz-transition: opacity 0.3s ease-in-out;
-o-transition: opacity 0.3s ease-in-out;
transition: opacity 0.3s ease-in-out;
}
.reveal:hover .hidden {
z-index: 100000;
opacity: 1;
}
.reveal .caption {
position: absolute;
top: 0;
display: table;
width: 100%;
height: 100%;
background-color: white; /* fallback for IE8 */
background-color: rgba(255, 255, 255, 0.7);
font: 13px/1.6 sans-serif;
text-transform: uppercase;
color: #333;
letter-spacing: 1px;
text-align: center;
text-rendering: optimizeLegibility;
}
.reveal .hidden .caption .centered {
display: table-cell;
vertical-align: middle;
}
@media (min-width: 480px) and (max-width: 979px) {
.reveal .caption {
font-size: 11px;
}
}
我的页面上没有任何变化。
最佳答案
检查这一。请根据需要更改SRC路径。希望能帮助到你。
.reveal{position: relative; width:300px; border:1px red solid; height:200px; margin: 0 auto}
.reveal img{ position: absolute; left:0; top:0; right:0; bottom:0; margin:0 auto; transition: all .3s ease-in-out;}
.grid-product__image{opacity:1}
.hidden{opacity:0;}
.reveal:hover .grid-product__image{opacity:0;}
.reveal:hover .hidden{opacity:1}
<div class="reveal">
<img class="grid-product__image" src="https://img.icons8.com/office/30/000000/address-book.png" alt="{{ image.alt | escape }}">
<img class="hidden" src="https://img.icons8.com/clouds/30/000000/business.png" alt="{{ product.images.last.alt | escape }}" />
</div>
关于html - 在悬停时显示不同的产品图片,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58375387/