views:

716

answers:

2

I'm having a problem with the mosueenter/mouseleave events only in Firefox...

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"&gt;&lt;/script&gt;
        <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. 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.

--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.

+1  A: 

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. Both of these seem to handle the range of possible mouse movement events rather than just mapping onto mouseenter/mouseleave.

tvanfosson
I just tried hover. Same problem.
AngrySpade
Apparently the bug only appears in Firefox 3.5.7, the bug is not reproducible in Firefox 3.6
AngrySpade
I have this erroneous behavior in FF 3.5.8 too.
MyGGaN
+2  A: 

This behavior is related to a firefox bug, that has been fixed in Firefox 3.6. jQuery tries to handle this bug with withinElement function (search through jQuery source code), but the solution isn't perfect.

Rafael