一个页面,分别用table中处理的,一共一个tr,2个td,每个td都加载了iframe,我现在想在中间增加一个td,当鼠标点击这个td的时候,实现拖动的效果,然后动态改变左右td的大小,要怎么处理啊?

解决方案 »

  1.   

    为啥要用td呢,想不通
    举例
    <table>
    <tr><td width="200px">左TD</td><td onmousedown="ini(this);" onmousemove="changewidth(this);" width="300px">移动的比较快,小心点</td><td width="200px">右TD</td></tr>
    </table>
    <script>
    window.document.onmouseup=function(){d=false;};
    var x;
    var d=false;
    function ini(o)
    {
    x=event.screenX;
    d=true;
    o.style.border="1px solid red";
    }
    function changewidth(o){if(d)o.previousSibling.width=((parseInt(o.previousSibling.width)+event.screenX-x)<0)?1:parseInt(o.previousSibling.width)+event.screenX-x;}
    </script>
    <div></div>
      

  2.   

    用offset移动起来好看些
    <table>
    <tr><td width="200px">左TD</td><td onmousedown="ini(this);" onmousemove="changewidth(this);" width="300px">移动的比较快,小心点</td><td width="200px">右TD</td></tr>
    </table>
    <script>
    window.document.onmouseup=function(){d=false;};
    var x;
    var d=false;
    function ini(o)
    {
    x=event.offsetX;
    d=true;
    o.style.border="1px solid red";
    }
    function changewidth(o){if(d)o.previousSibling.width=(parseInt(o.previousSibling.width)+event.offsetX-x)<0?1:parseInt(o.previousSibling.width)+event.offsetX-x;}
    </script>
    <div></div>
      

  3.   

    谢谢ls的,可惜我的是用百分比设定大小的。用td的原因是,左右两个td中分别用iframe加载了其他的内容。因为左边的内容太宽而看不到,虽然有滚动条可用户还是觉得能有个动态改变大小的,可以拖动的。
      

  4.   

    貌似对TABLE的子元素 的操作不是那么利索
     建议换成一个DIV中间套3个TABLE的 或者中间套3个DIV的