• 一款JavaScript代码,实现的效果是使被嵌套的表格可以在外层表格中拖动,而不能超出外表格的边框,类似层的拖动效果。


点击(此处)折叠或打开

  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
  4. <title>石家庄自动门</title>
  5. </head>
  6. <body>
  7. <script>
  8. var isDraging=false;var ox,oy;function fnDown()
  9. {
  10. isDraging=true;
  11. ox=event.offsetX;
  12. oy=event.offsetY;
  13. mid.setCapture();}
  14. function fnMove()
  15. {if(event.button!=1)
  16. fnRelease();
  17. if(isDraging){
  18. var th=event.y-oTable.offsetTop-oy;
  19. if (th<1) th=1;
  20. if(th+parseInt(mid.height)>parseInt(oTable.height))
  21. th=parseInt(oTable.height)-parseInt(mid.height);
  22. up.height=th;
  23.  }
  24.  }
  25.  function fnUp(){fnRelease();
  26.  }
  27.  function
  28.  fnRelease()
  29.  {
  30.  isDraging=false;
  31.  mid.releaseCapture();}</script>
  32.  <BODY>
  33.  <TABLE id=oTable width=360 height=312 border=1 cellspacing="0" cellpadding="0" >
  34.  <TR>
  35.  <TD id=up bgColor=#0066CC></TD></TR>
  36.  <TR>
  37.  <TD id=mid height=38 bgColor=#000000 onmousedown="fnDown()" onmousemove="fnMove()" onmouseup="fnUp"></TD>
  38.  </TR>
  39.  <TR>
  40.  <TD id=down bgColor=#0066CC></TD></TR>
  41.  </TABLE>
  42. </body>
  43. </html>


10-20 22:12