开发者

jquery mouseleave issue when moving too slow

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) ;
        }
    });
});


Try to use hover instead mouseenter and mouseleave;

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜