2014-09-21 79 views
1

它在Chrome中正常工作,但不是在Firefox中,在Firefox中它會在觸發器之外觸發,然後移動光標。任何想法是什麼導致這種行爲,有沒有辦法解決它?點擊並拖動溢出元素:隱藏不會觸發onmouseout在Firefox中

var testDiv = document.getElementById("testDiv"); 
 
testDiv.onmouseout = function() { 
 
    alert("Triggered."); 
 
};
#testDiv { 
 
    overflow: hidden; 
 
    width: 100px; 
 
    height: 100px; 
 
    background-color: green; 
 
}
<div id="testDiv"></div>

所以單擊並按住綠色廣場裏話外移動光標。上的jsfiddle

鏡:http://jsfiddle.net/5ntLgyow/

+0

一旦我將鼠標移出盒子後,它就會觸發。這不適合你嗎? – Brian 2014-09-21 00:27:39

+0

是的,但是爲什麼它不像鉻合金一樣,在你離開盒子時觸發正確? – Mandera 2014-09-21 00:29:07

+0

您的Firefox版本是什麼? – Hamix 2014-09-21 11:18:17

回答

0

添加的最後一行。 firefox有默認的拖拽功能,所以可以防止鼠標拖曳時的默認值。

var testDiv = document.getElementById("testDiv"); 
testDiv.onmouseout = function() { 
    alert("Triggered."); 
}; 

testDiv.onmousedown=function(e){e.preventDefault();}