jQuery mouseleave function isn't being triggered when mouse moves quickly

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-04 04:23:17

EDIT

Okay new plan!

Try this:

$('#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);         
    });
});

I didn't click that you are running animations on two separate objects! Feeling more confident about this one!

I've seen this before. When you move the mouse fast enough, it just skips over to a new place and doesn't trigger the mouseleave action. here's my solution using just a little bit of jQuery. Basically, while you are hovering on the pin, you need to bind a listener to the window that looks for any mouse movement and checks that you are still hovering on the pin. I dont' think you'd want this listener running all the time, so I have it unbind itself.

$(".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");
    }
  }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!