簡體   English   中英

Firefox中的jQuery Mouseenter / Mouseleave問題

[英]Problem with jQuery Mouseenter/Mouseleave in Firefox

我只在Firefox中遇到mosueenter / mouseleave事件的問題...

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>

我只想知道鼠標何時離開了包含DIV。 但是,如果您將鼠標移動到文本框上非常快,或者將鼠標移動到div的滾動條上,則會觸發事件。

- 編輯 -

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

我在懸停時嘗試了以下操作。 它似乎僅在Firefox中遭受同樣的問題。

我幾乎總是發現,如果您計划在鼠標進入和離開元素時同時執行操作,最好使用hover()方法或hoverIntent()插件而不是單獨的mouseenter / mouseleave處理程序。 這兩者似乎都處理了可能的鼠標移動事件的范圍,而不僅僅是映射到mouseenter / mouseleave。

此行為與firefox錯誤有關,已在Firefox 3.6中修復。 jQuery嘗試使用withinElement函數來處理這個bug(通過jQuery源代碼搜索),但解決方案並不完美。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM