Adding a delay on mouseout with jquery
I'm writing a function to fire a fadein - fadeout effect on mouseover / mouseout, all works right, but now I need to add a delay on mouseout. When the mouse hovering a link the div related has to fadein and the other ones need to fadeout.
I try many times without any success...
Here's the code:
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);
});
});
}
Thanks so much!
您不能延迟触发事件,但可以在使用setTimeout
函数执行的代码中添加延迟
上一篇: 控制并转换为XPS