我希望div a
和div b
在鼠标结束时切换位置div b
然后在鼠标离开时切换回div a
。但它的超级毛病,即使鼠标没有离开div a
也会切换。当鼠标仍然在div a
时,我如何获得它到而不是运行navMouseOut
,为什么它这样做。 (请测试代码,看看什么错)onmouseover with javascript
document.getElementById("b").onmouseover = function() {
navMouseOver()
};
document.getElementById("a").onmouseout = function() {
navMouseOut()
};
function navMouseOver() {
document.getElementById("a").style = ("top: 50%;");
document.getElementById("b").style = ("top: 40%; ");
}
function navMouseOut() {
document.getElementById("a").style = ("top: 40%;");
document.getElementById("b").style = ("top: 50%;");
}
#a {
position: fixed;
top: 40%;
left: 20%;
background-color: red;
}
#b {
position: fixed;
top: 50%;
left: 20%;
background-color: lightblue;
}
<div id="a">
<p>content a</p>
</div>
<div id="b">
<p>content b...</p>
</div>
顺便说一句,你不需要匿名函数包装到其他函数的调用,只是说'的document.getElementById( “B”)的onmouseover = navMouseOver;'。 – nnnnnn