【发布时间】:2016-08-15 06:34:57
【问题描述】:
所以我有一堆元素,例如:
<div class="hover-icon one">
<img class="original" src="sswe-images/Circle_Customer Notifications.png"/>
<img class="hovered one" src="sswe-images/Customer-Notifications.gif" />
</div>
<div class="hover-icon two">
<img class="original" src="sswe-images/Circle_Field Service Tools.png" />
<img class="hovered" src="sswe-images/Field-Service-Tools.gif" />
</div>
<div class="hover-icon three">
<img class="original" src="sswe-images/Circle_Remote Connectivity.png" />
<img class="hovered" src="sswe-images/Remote-Connectivity.gif" />
</div>
.original 是占位符,.hovered 是我想在悬停时制作动画的 gif,然后在鼠标离开后恢复正常状态。我的尝试是:
$('div.hover-icon').hover(function(){
var orig = $(this).find('.original');
orig.hide();
var hov = $(this).find('.hovered');
hov.attr('src', hov.attr('src') + "?x=" + Math.random());
setTimeout(function(){ hov.show(); }, 100);
/* $(this).mouseleave(function(){
hov.hide();
orig.show();
});*/
});
但注释掉部分的原因是它不起作用。它引起了各种疯狂。我应该在这里使用什么正确的模式?
【问题讨论】:
-
如果你想支持 CSS3,可能有更简洁的方法来做到这一点。 Google 搜索“css gif 动画开始停止”会发现很多可能性。
-
最简单的解决方案是有一个简单的图像,并在悬停时将其替换为 GIF 图像。
标签: javascript jquery html css gif