日期:2014-05-16  浏览次数:20660 次

如何实现,动态改变左侧Div宽度?
页面有左右两个Div并列,其中左侧宽度固定,右侧大小自动;

我想用中间id=ctrl的Div竖条,来动态控制左侧的宽度,谁有时间帮解决下,谢谢了。

HTML code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" 
"http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
<title>无标题文档</title> 
<style type="text/css"> 
<!-- 
body{ height:100%; overflow:hidden;    margin: 0px; font-size:12px; background-color: #E1EEFD; }
.wrapper{    width: 100%;    height:100%;} 
.left    {    width:300px;    height:100%; position:absolute; left:0; top:140; z-index:1; overflow:auto;  background-color:#CCFF66;} 
.right    {    width:100%;        height:100%;     position:absolute; left:0; top:140;  background-color:#0066FF; } 
.content{    margin-left:300px; height:100%;    padding-left:10px;  padding-top:0px; } 
.center{ margin-left:300px; width:10px;    height:100%;  position:absolute;  left:10;  top:140;  z-index:2; background-color:#FF6600; } 
--> 
</style> 
</head> 
<body> 
    <div id="wrapper" class="wrapper">
        <div id = "left" class="left">
            左侧
        </div>
        <div id="ctrl" class="center">
        </div>
        <div id = "right" class="right"> 
            <div class="content"> 右侧 </div> 
        </div> 
    </div>
</div> 
</body> 
</html> 


------解决方案--------------------
不知道是不是这个意思

HTML code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"  "http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"/> 
<title>无标题文档</title> 
<style type="text/css"> 
body{ height:100%; overflow:hidden;    margin: 0px; font-size:12px; background-color: #E1EEFD; }
.wrapper{ width: 100%;    height:100%;} 
.left    {  width:300px;    height:100%; position:absolute; left:0; top:140; z-index:1; overflow:auto;  background-color:#CCFF66;} 
.right    { width:100%;        height:100%;     position:absolute; left:0; top:140;  background-color:#0066FF; } 
.content{ height:100%;    padding-left:10px;  padding-top:0px; } 
.center{ left:300px; width:10px;    height:100%;  position:absolute;  left:10;  top:140;  z-index:2; background-color:#FF6600; cursor:col-resize;} 

</style> 
</head> 
<body> 
    <div id="wrapper" class="wrapper">
        <div id = "left" class="left">
            左侧
        </div>
        <div id="ctrl" class="center">
        </div>
        <div id = "right" class="right"> 
            <div class="content"> 右侧 </div> 
        </div> 
    </div> 
    <script type="text/javascript">
    var oldPos={lw:0,l:0,ex:0},isIE=!!document.all,isMove=false;
    function $(Id){return document.getElementById(Id);}
    function getL(o){
       if(o.style.left)return parseInt(o.style.left,10);
       var l=o.offsetLeft;
       while(o=o.offsetParent)l+=o.offsetLeft;
       return l;
    }
    window.onload=function(){
      var dv=$('ctrl');
      dv.onmousedown=function(e){
        e=e||event;
        isMove=true;
        if(isIE)this.setCapture();
        oldPos.l=getL(this);
        oldPos.ex=e.clientX;
        var l=$('left');
        oldPos.lw=l.style.width?parseInt(l.style.width,10):l.offsetWidth;
      }
      dv.onmouseup=function(){
        if(i