jquery mouseleave issue when moving too slow

跟風遠走 提交于 2019-12-20 01:43:17

问题


I am using the jQuery mouseenter and mouseleave events to slide a div down and up.

Everything works well except for the mouseleave which doesn't appear to fire ONLY if the mouse of moved off of the div quite slowly. If i move the mouse at a relatively normal or fast speed then it works as expected.

Can anyone explain this or provide any info on how to get around this?

Code:

$(document).ready(function() {
    $('header').mouseenter(function() {
        $(this).stop().animate({'top' : '25px'}, 500, function() {
            $(this).delay(600).animate({'top' : '-50px'}, 500);
        });
    }).mouseleave(function(e) {
        var position = $(this).position();
        if (e.pageY > position.top + $(this).height()) {
            $(this).stop().delay(600).animate({'top' : '-75px'}, 500) ;
        }
    });
});

回答1:


Try to use hover instead mouseenter and mouseleave;

$(document).ready(function() {
    $("#div").hover(function() {
         $("#something").slideDown(400);
    }, function() {
         $("#something").slideUp(400);
    });
});


来源:https://stackoverflow.com/questions/4500321/jquery-mouseleave-issue-when-moving-too-slow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!