就好像这功能。
代码如下
<style> #div1{ width:50px; height:50px; background:red; margin-bottom:10px; } #div2{ width:200px; height:200px; background:black; display:none; } </style> <body> <div id="div1"></div> <div id="div2"></div> </body>
<script>
window.οnlοad=function()
{
var div1=document.getElementById("div1");
var div2=document.getElementById('div2');
var timer=null;
div1.οnmοuseοver= function()
{
div2.style.display='block';
};
div1.οnmοuseοut= function()
{
clearTimeout(timer);
timer= setTimeout(function()
{
div2.style.display='none';
}, 500)
};
div2.οnmοuseοver=function()
{
clearTimeout(timer);
};
div2.οnmοuseοut=function(){
timer=setTimeout(function(){div2.style.display='none';},500);
}
}
</script>
为什么要用延时器,
因为当移动另外一个模块时需要一定的时间,延时,鼠标能有一定的时间移到新的模块。