其他分享
首页 > 其他分享> > 移动太慢时的jquery mouseleave问题

移动太慢时的jquery mouseleave问题

作者:互联网

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

一切正常,除了mouseleave似乎只有在将div的鼠标移离div很慢时才会触发.如果我以相对正常或较快的速度移动鼠标,则它将按预期工作.

谁能解释这个问题或提供任何有关如何解决此问题的信息?

码:

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

解决方法:

尝试使用鼠标悬停代替mouseenter和mouseleave;

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

标签:javascript,jquery,mouseleave
来源: https://codeday.me/bug/20191011/1891404.html