鼠标悬停显示(/隐藏)DIV
效果:
(1)
(2)
源码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>鼠标悬停显示DIV</title>
</head>
<body>
<div id="b1" style="width: 200px;height: 50px;background-color: red">1111111</div>
<div id="b2" style="width: 200px;height: 50px;margin-left: 220px;margin-top: -50px; background-color: yellow">2222222</div>
<div id="v1" style="width: 400px;height: 200px;background-color: red;">111</div>
<div id="v2" style="width: 400px;height: 200px;background-color: yellow;">222</div>
<script>
window.onload = function(){
var aa = document.getElementById("b1");
var bb = document.getElementById("b2");
var xx = document.getElementById("v1");
var yy = document.getElementById("v2");
xx.style.display = "none";
yy.style.display = "none";
aa.onmouseover = function(){
xx.style.display = "block";
yy.style.display = "none";
};
aa.onmouseout = function(){
xx.style.display = "block";
yy.style.display = "none";
};
bb.onmouseover = function(){
yy.style.display = "block";
xx.style.display = "none";
};
bb.onmouseout = function(){
yy.style.display = "block";
xx.style.display = "none";
};
};
</script>
</body>
</html>