html - 悬停时显示不同的产品图片

标签 html css shopify liquid

我试图在我的产品系列页面上悬停时显示不同的产品图片。 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/

相关文章:

javascript - 如何使用 Node Js 创建 session ?

javascript - 在 Highcharts 漏斗可视化的左侧或右侧添加标签

css - 播放 html5 iOS Cordova 视频时的阴空白灰色按钮

ruby-on-rails - rails : Shopify integration withouth a shopify app?

javascript - 如何在用户单击任何图像时创建弹出窗口?

python - 使用其 python api 在 shopify 中创建带有图像 URL 的新产品

html - 弄清楚过渡

html - 如何构建具有固定宽度和 100% 边的居中菜单

html - 表格 HTML 的不同样式

css - 没有大小的元素使用位置 : absolute, 在上面动态插入 block - 正确的行为是什么?