jquery mouseover事件发射两次 [英] jquery mouseover event firing twice

查看:78
本文介绍了jquery mouseover事件发射两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

    $(function(){
    $('#webs').mouseenter(function(){
        $('#websitehov').fadeIn('slow');
    });
    $('#webs').mouseleave(function(){
        $('#websitehov').fadeOut('slow');
    });
});

我知道这里有很多问题,但我已经尝试了很多,但仍然不工作,我尝试了不同的事件处理程序,包括.hover,.mouseover和.mouseenter。
图像悬停/悬停效果在进入时会多次触发,每当我在图像中移动鼠标时,两个事件开始触发。
我发现了一个解决方案,可以阻止它:

I know there are a ton of questions on this but I've tried a number of them and still not working, I've tried different event handlers including .hover, .mouseover and .mouseenter. The image hover/hover out effect fires multiple times when it enters and whenever I move the mouse inside the image the two events start firing. I found one solution that stopped this :

(function(){
$('#webs').hover(function(){
$('#websitehov').fadeIn('slow')
}, function() { });
});

但这只适用于悬停,不能悬停,因为空函数是mouseout事件处理程序,IDK,如果你可以重写这个?

but this only worked for the hover in and not for hover out because the empty function was the mouseout event handler, idk if you can override this?

推荐答案

我可以看到的唯一可能的问题是动画排队,清除动画在添加另一个之前排队

The only possible problem I can see is that of animation queuing, clear the animation queue before addition another one

$(function () {
    $('#webs').hover(function () {
        $('#websitehov').stop(true, true).fadeIn('slow');
    }, function () {
        $('#websitehov').stop(true, true).fadeOut('slow');
    });
});

演示:小提琴

这篇关于jquery mouseover事件发射两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆