#如上图的div1 和div 2两个块是相互独立的,div2的初始状态是不显示,display为none,
,当鼠标移动到div1元素中时,div2显示。但是当鼠标离开div1并且不进入div2时,div2消失。
如果鼠标离开div1进入div2,div2保持显示状态。如果鼠标离开div2,进入div1,div2继续显示。如果鼠标离开div2并且不进入div1,div2消失。
<div id="xiao" style="width:30px;height: 20px;margin: 0 auto;border:1px black solid">
</div>
<div id="da" style="width:300px;height: 200px;margin: 0 auto;display: none;border:1px black solid">
</div>
$("#xiao,#da").bind("mouseover",function () {
$("#da").css({"display":"block"});
}).bind("mouseout",function () {
$("#da").css({"display":"none"});
});
利用鼠标的mouseover事件
用的是jQuery写的!!!!!!!!!!!!!!!
#div1{ height: 100px; width: 200px; background: #999; } #div2{ height: 500px; width: 1000px; background: #919; display:none; } <body>
<div id="div1" onclick="showdiv()">div1</div>
<div id="div2">div2</div>
</body>
$("#div1").mouseover(function(){ $("#div2").show(); }); $("#div1").mouseleave(function(){ $("#div2").hide(); }); $("#div2").mouseover(function(){ $("#div2").show(); }); $("#div2").mouseleave(function(){ $("#div2").hide(); });<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script src="jquery-3.2.1.min.js"></script>
<title>互联</title>
<style>
#div1{ height: 100px; width: 200px; background: #999; }
#div2{ height: 500px; width: 1000px; background: #919; display:none; }
</style>
</head>
<body>
<div id="div1" onclick="showdiv()">div1</div>
<div id="div2">div2</div>
</body>
<script>
$("#div1").mouseover(function(){
$("#div2").show();
});
$("#div1").mouseleave(function(){
$("#div2").hide();
});
$("#div2").mouseover(function(){
$("#div2").show();
});
$("#div2").mouseleave(function(){
$("#div2").hide();
});
</script>
</html>
不要通过列表的形式实现,比如下面的其实不符合情况,我的是两个互相独立的div:
<!DOCTYPE html>