【发布时间】:2014-06-19 21:59:56
【问题描述】:
我正在尝试将 shopify 平台用于小型商业网站。我在我的主要收藏页面上构建了大部分网站,但我希望为项目的正面/背面设置图像悬停效果。目前我的 html 是这样输出的,其中产品列表中的第一项和第二项在 div 中列出。它的工作方式。基本上我想让图像在页面加载时淡入淡出,当悬停在淡出上时,然后淡入 div 中的第二个图像,当悬停叶恢复到原始图像时。
.html
<div class="image">
<a href="{{ product.url | within: collection }}">
<img src="{{ product.featured_image.src | product_img_url: 'large' }}" alt="{{ product.featured_image.alt | escape }}"class="img-responsive collectionItem">
<img src="{{ product.images[1] | product_img_url: 'large' }}" alt="{{ product.title | escape }}" class="img-responsive collectionItem" style="display:none"/>
</a>
</div>
.js
$('.collectionItem').hover(function() {
$(this).fadeOut();
$(this).next('img').stop(true, true).fadeIn('slow');
}, function() {
$(this).next('img').fadeOut();
$(this).stop(true, true).fadeIn('slow');
});
【问题讨论】:
-
旁注:重复
$(this)选择器是浪费处理。使用局部变量(当最小化时,代码也更短作为奖励)。 -
计划在我想出正确淡入和淡出而不闪烁的最佳方法后
标签: javascript jquery html css