<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<style>
*{ margin:0; padding:0;}
.div{ position:relative;width:980px;height:50px; float:left;margin-top:500px;margin-left:100px;}
.D1{width:50px; height:50px; background:#CCC;}
.D2{width:100px; height:100px; background:#066; position:absolute;top:-120px;left:-30px;
display:none;}
</style>
<script>
window.onload=function () 

  /* var oDiv1=document.getElementById('div1');
   var oDiv2=document.getElementById('div2');
   var Time=null;
   oDiv1.onmouseover=oDiv2.onmouseover=function(){
   clearTimeout(Time);
   oDiv2.style.display='block';
   }
   oDiv1.onmouseout=oDiv2.onmouseout=function(){
   Time=setTimeout(function(){
   oDiv2.style.display='none';
   },500)
   }*/
   var oDiv = document.getElementById('div1');
   
        oDiv.onmouseover = function () {
            startMove(100);
        }
        oDiv.onmouseout = function () {
            startMove(50);
        }
}; 
//创建运动框架
var timer=null;
function startMove(iTarget){//创建目标
var oDiv1=document.getElementById('div2');
clearInterval(timer)//关闭定时器
    timer=setInterval(function(){//开启定时器
var speed=0;
if(iTarget==100){
speed=10;
}else{
speed=-10;
}
if(oDiv1.offsetHeight==iTarget){
clearInterval(timer);
}else{
oDiv1.style.height=oDiv1.offsetHeight+speed+'px';
}
},30)
}
</script>
</head><body>
<div class="div">
<div class="D1" id="div1"></div>
<div class="D2" id="div2"></div>
</div>
</body>
</html>为什么 id="div2"的div 不显示

解决方案 »

  1.   

    样式里面设置了class为D2的隐藏<style>
    *{ margin:0; padding:0;}
    .div{ position:relative;width:980px;height:50px; float:left;margin-top:500px;margin-left:100px;}
    .D1{width:50px; height:50px; background:#CCC;}
    .D2{width:100px; height:100px; background:#066; position:absolute;top:-120px;left:-30px;
    display:none;}//把display:none; 去掉就可
    </style>
      

  2.   

    如果把 display:none 去掉了 可是我D2里面的内容就不能隐藏了 请问下有没有什么方法啊
      

  3.   

    如果把 display:none 去掉了 可是我D2里面的内容就不能隐藏了 请问下有没有什么方法啊
    那就在函数里面显示D2
    //创建运动框架
    var timer=null;
    function startMove(iTarget){//创建目标
    var oDiv1=document.getElementById('div2');
    oDiv1.style.display = "block";//加上这一句显示D2
    clearInterval(timer)//关闭定时器
        timer=setInterval(function(){//开启定时器
    var speed=0;
    if(iTarget==100){
    speed=10;
    }else{
    speed=-10;
    }
    if(oDiv1.offsetHeight==iTarget){
    clearInterval(timer);
    }else{
    oDiv1.style.height=oDiv1.offsetHeight+speed+'px';
    }
    },30)
    }
      

  4.   

    如果把 display:none 去掉了 可是我D2里面的内容就不能隐藏了 请问下有没有什么方法啊
    那就在函数里面显示D2
    //创建运动框架
    var timer=null;
    function startMove(iTarget){//创建目标
    var oDiv1=document.getElementById('div2');
    oDiv1.style.display = "block";//加上这一句显示D2
    clearInterval(timer)//关闭定时器
        timer=setInterval(function(){//开启定时器
    var speed=0;
    if(iTarget==100){
    speed=10;
    }else{
    speed=-10;
    }
    if(oDiv1.offsetHeight==iTarget){
    clearInterval(timer);
    }else{
    oDiv1.style.height=oDiv1.offsetHeight+speed+'px';
    }
    },30)
    }

    你这样就直接把 内容显示出来啊 我是想内容跟div刚刚开始都是隐藏的 内容跟随div的显示而显示出来的
      

  5.   


    //创建运动框架
    var timer=null;
    function startMove(iTarget){//创建目标
    var oDiv1=document.getElementById('div2');
    clearInterval(timer)//关闭定时器
        timer=setInterval(function(){//开启定时器
    var speed=0;
    if(iTarget==100){
    speed=10;
    }else{
    speed=-10;
    }
    if(oDiv1.offsetHeight==iTarget){
    clearInterval(timer);
    oDiv1.style.display = "none";
    }else{
    oDiv1.style.height=oDiv1.offsetHeight+speed+'px';
    }
    oDiv1.style.display = "block";
    },30)
    }鼠标移进去div1渐变显示div2,移出渐变隐藏div2到一半高度
    这样之后还需要隐藏掉div2么