<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#db1").click(function(){
  if($("#db2").css('width') == '200px'){
  $("#db2").animate({width:0},"slow");
  $("#hide").val('显示');
}else{
$("#db2").animate({width:200},"slow");
$("#hide").val('隐藏');
}
});
});
</script>
<div style=" width:800px; height:600px; background:#CCCCCC; position:relative">
<div style="width:200px; height:30px; background:#00FF00; float:right; margin-top:40px;" id="db2">111</div>
<div style=" width:150px; height:100px; background:#006699; right:200px; top:20px; cursor:pointer; position: absolute" id="db1">点击<input type="hidden" id="hide"  value="隐藏" /></div>
</div>效果没做对,绿色框应该是从右往左消失的,现在反了
而且总体感觉也不怎么对

解决方案 »

  1.   

    通过把绿框加长,然后用蓝框遮盖,倒是能实现的了,不过,感觉还是有问题<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
      $("#db1").click(function(){
      if($("#db2").css('width') == '350px'){
      $("#db2").animate({width:150},"slow");
      $("#hide").val('显示');
    }else{
    $("#db2").animate({width:350},"slow");
    $("#hide").val('隐藏');
    }
    });
    });
    </script>
    <div style=" width:800px; height:600px; background:#CCCCCC; position:relative; float:left">
    <div style=" height:30px; background:#00FF00; margin-left:450px; width:350px; margin-top:40px;" id="db2">111</div>
    <div style=" width:150px; height:100px; background:#006699; right:200px; top:20px; cursor:pointer; position: absolute" id="db1">点击<input type="hidden" id="hide"  value="隐藏" /></div>
    <div style="clear:both"></div>
    </div>
      

  2.   

    把db2 改成绝对定位<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
      $("#db1").click(function(){
       
      if($("#db2").css('width') == '200px'){
      $("#db2").animate({width:0},"slow");
      $("#hide").val('显示');
    }else{
    $("#db2").animate({width:200},"slow");
    $("#hide").val('隐藏');

    });
    });
    </script>
    <div style=" width:800px; height:600px; background:#CCCCCC; position:relative">
    <div style="width:200px; height:30px; background:#00FF00; position: absolute; left:600px;   margin-top:40px;" id="db2">111</div>
    <div style=" width:150px; height:100px; background:#006699; right:200px; top:20px; cursor:pointer; position: absolute" id="db1">点击<input type="hidden" id="hide"  value="隐藏" /></div>
    </div>
      

  3.   

    其实不用db2绝对定位,我在2楼写的改下宽度就行,不知道为啥我还整出个遮盖不过还是有点小问题,db2里的文字无法去掉。。难道要给清空??另外这么写对么??
      

  4.   

    你 db1 是绝对定位,层次比db2前,如果你要求两个要交叠,只能把 db2也用绝对定位,不交叠就是把db1向左移些
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js"></script>
    <script>
    $(document).ready(function(){
      $("#db1").click(function(){
     
    if($("#db2").css('width') == '350px'){
      $("#db2").animate({width:0  },"slow",function(){ $(this).hide() });
      $("#hide").val('显示');
    }else{
    $("#db2").show().animate({width:350,display:'block'},"slow" );
    $("#hide").val('隐藏');




    });
    });
    </script>
    <div style=" width:800px; height:600px; background:#CCCCCC; position:relative; float:left">
    <div style=" height:30px; background:#00FF00; margin-left:450px; width:350px; margin-top:40px;" id="db2">111</div>
    <div style=" width:150px; height:100px; background:#006699; right:350px; top:20px; cursor:pointer; position: absolute" id="db1">点击<input type="hidden" id="hide"  value="隐藏" /></div>
    <div style="clear:both"></div>
    </div>