使用jquery在mouseout上添加延迟
我正在编写一个函数来触发一个淡入淡出效果 - 对鼠标悬停/鼠标悬停的淡出效果,所有作品都是正确的,但现在我需要在mouseout上添加延迟。 当鼠标悬停一个链接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);
                });
            });
    }
非常感谢!
您不能延迟触发事件,但可以在使用setTimeout函数执行的代码中添加延迟
