简体   繁体   English

Firefox中的jQuery Mouseenter / Mouseleave问题

[英]Problem with jQuery Mouseenter/Mouseleave in Firefox

I'm having a problem with the mosueenter/mouseleave events only in Firefox... 我只在Firefox中遇到mosueenter / mouseleave事件的问题...

http://www.screencast.com/users/StanleyGoldman/folders/Jing/media/be3572de-9c72-4e2a-8ead-6d29b0764709 http://www.screencast.com/users/StanleyGoldman/folders/Jing/media/be3572de-9c72-4e2a-8ead-6d29b0764709

<HTML>
    <HEAD>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.js"></script>
        <script>
            $(document).ready(function() {
                $("#theDiv").mouseenter(function() {
                    $("#output").append('mouseenter<br>'); 
                });
                $("#theDiv").mouseleave(function() {
                    $("#output").append('mouseleave<br>');
                });
            });

        </script>
    </HEAD>
    <BODY>

    <div id="theDiv" style="position:relative; height: 300px; width:300px; background-color:Black;">
        <input type="text" style="position:absolute; top: 40px;" />

        <div style="position:absolute; top:100px; height:100px; width:100px; background-color:Red; overflow:auto;">
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        <p>Content</p>
        </div>
    </div>

    <div id="output"></div>

    </BODY>
</HTML>

I only want to know when the mouse has left the containing DIV. 我只想知道鼠标何时离开了包含DIV。 But if you either move the mouse over a textbox really fast or move the mouse over the scrollbar of a div, the events fire. 但是,如果您将鼠标移动到文本框上非常快,或者将鼠标移动到div的滚动条上,则会触发事件。

--EDIT-- - 编辑 -

$("#theDiv").hover(function() {
    $("#output").append('hoverin<br>');
}, function() {
    $("#output").append('hoverout<br>');
});

I tried the following with hover. 我在悬停时尝试了以下操作。 It seems to suffer from the same issue only in Firefox. 它似乎仅在Firefox中遭受同样的问题。

I almost always find that it's better to use the hover() method or the hoverIntent() plugin rather than separate mouseenter/mouseleave handlers if you are planning to do things both when the mouse enters and leaves an element. 我几乎总是发现,如果您计划在鼠标进入和离开元素时同时执行操作,最好使用hover()方法或hoverIntent()插件而不是单独的mouseenter / mouseleave处理程序。 Both of these seem to handle the range of possible mouse movement events rather than just mapping onto mouseenter/mouseleave. 这两者似乎都处理了可能的鼠标移动事件的范围,而不仅仅是映射到mouseenter / mouseleave。

This behavior is related to a firefox bug , that has been fixed in Firefox 3.6. 此行为与firefox错误有关,已在Firefox 3.6中修复。 jQuery tries to handle this bug with withinElement function (search through jQuery source code), but the solution isn't perfect. jQuery尝试使用withinElement函数来处理这个bug(通过jQuery源代码搜索),但解决方案并不完美。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM