2011-05-26 118 views
7

我有其中当鼠标悬停在其上的小销的时间轴,向上或向下滑动,然后显示字幕不被触发。当鼠标离开时,标题应该消失并且引脚向后移动。这是有效的,但是对于我使用的代码,如果鼠标移动太快,它不会检测到鼠标离开。我怎样才能解决这个问题?jQuery的鼠标离开功能时鼠标移动很快

P.S,我使用鼠标进入/离开的唯一原因是因为我觉得我需要使用活的()为我的元素在文档加载后动态添加。

$('#about-me .progress-bar .progress .notes li.personal').live('mouseenter',function(){ 
    $(this).animate({ 
     top:25 
    }, 200, function(){ 
     $(this).find('.caption').stop(true, true).fadeIn(200); 
    });  
}).live('mouseleave',function(){ 
    $(this).find('.caption').stop(true, true).delay(200).fadeOut(200,function(){ 
     $(this).parents('li').animate({ 
      top:30 
     },200);   
    }); 
}); 
+0

当你说它没有检测到mouseleave,如果你用alert('test')替换mouseleave函数,这是不是会触发? – lnrbob 2011-05-26 20:22:30

+0

哦,它确实:( 的标题就是不淡出,销不动画>。< – Henryz 2011-05-26 20:26:33

+0

知道为什么这可能是发生? – Henryz 2011-05-26 20:27:13

回答

5

编辑

好了新的计划!

试试这个:

$('#about-me .progress-bar .progress .notes li.personal').live('mouseenter',function(){ 
    $(this).animate({ 
     top:25 
    }, 200, function(){ 
     $(this).find('.caption').stop(true, true).fadeIn(200); 
    });  
}).live('mouseleave',function(){ 
    $(this).stop(true, true).find('.caption').stop(true, true).delay(200).fadeOut(200,function(){ 
     $(this).parents('li').animate({ 
      top:30 
     },200);   
    }); 
}); 

我没点击你正在运行在两个不同的对象的动画!感觉这个更有信心!

+0

他们仍然会被卡住不幸的是。他们不会,如果我慢慢地移动我的鼠标。 – Henryz 2011-05-26 20:31:35

+0

尝试改变'.stop(真,真).fadeIn'为'.stop()fadeIn' - 这似乎已经纠正在我的测试行为 - 可能有虽然 – lnrbob 2011-05-26 20:40:16

+0

你天才一敲!为我保留了一个正确的头痛。我可以问你如何解决?我知道你在find()之前添加了stop(),但是为什么? 再次感谢,感激不尽。 – Henryz 2011-05-26 20:53:02

2

我以前见过这个。当你移动鼠标足够快时,它会跳到一个新的地方,并不会触发mouseleave动作。这里是我的解决方案,只使用一点jQuery。基本上,当你悬停在引脚上时,你需要将侦听器绑定到寻找鼠标移动的窗口,并检查你是否仍然在引脚上徘徊。我不认为你会希望这个倾听者一直在跑,所以我让它解开了自己。

$(".pin").live("mouseenter", function(event) { 
    var pin = $(event.target); 
    // show the caption 
    pin.addClass("hovered"); 

    $(window).bind("mousemove", function(event) { 
    var target = $(event.target); 
    if (!target.hasClass("hovered")) { 
     // hide the caption  
     $(".hovered").removeClass("hovered"); 
     $(window).unbind("mousemove"); 
    } 
    } 
}
+0

感谢您的回答muirbot,这实际上帮我别的东西,但Inrbob的回答固定的这个问题。 – Henryz 2011-05-27 09:40:17

相关问题