它在chrome中可以正常工作,但在Firefox中却不能正常工作,在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/

最佳答案

添加最后一行。 firefox具有默认的拖动功能,因此可以防止鼠标向下默认设置。

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

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

关于javascript - 单击并拖动带有溢出的元素:隐藏不会在firefox中触发onmouseout,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/25954557/

10-12 13:11