移动太慢时jquery mouseleave问题 [英] jquery mouseleave issue when moving too slow

查看:62
本文介绍了移动太慢时jquery mouseleave问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jQuery mouseenter和mouseleave事件来向上和向下滑动div。

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

一切都很好,除了鼠标保护之外似乎只会触发如果鼠标移动div很慢。如果我以相对正常或快速的速度移动鼠标,那么它会按预期工作。

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?

代码:

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


推荐答案

尝试使用hover而不是mouseenter和mouseleave;

Try to use hover instead mouseenter and mouseleave;

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

这篇关于移动太慢时jquery mouseleave问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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