【发布时间】:2016-01-29 01:14:46
【问题描述】:
我正在编写一个函数来触发鼠标悬停/鼠标移出的淡入淡出效果,一切正常,但现在我需要在鼠标移出时添加延迟。 当鼠标悬停在链接上时,相关的 div 必须淡入,而其他的需要淡出。
我试了很多次都没有成功...
代码如下:
function selectedSwitch() {
$('.selectedSwitch').each(function() {
$(this).on("mouseover", function(e) {
e.preventDefault();
var current = $(this).data('selected');
$('.selected.post-'+current).stop().animate({'opacity': 1}, 200);
$('.selected.post-'+current).siblings().stop().animate({'opacity': 0}, 200);
});
$(this).on("mouseout", function(e) {
e.preventDefault();
var current = $(this).data('selected');
$('.selected.post-'+current).stop().animate({'opacity': 0}, 200);
});
});
}
非常感谢!
【问题讨论】:
-
我不太明白这个问题。您是否要等到第一个动画完成后再做 mouseout 动画?