js 拉伸拖动iframe框架的简单示例

前端之家收集整理的这篇文章主要介绍了js 拉伸拖动iframe框架的简单示例前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
左边iframe放树目录,右边的iframe放index页。拖鼠标同时控制2个iframe的宽高。
期待有人能改进。
操作方法:鼠标指到2个iframe中间,可以水平拖,纵向拖(控制高度)
缺点:CSDN页面放开鼠标后才改大小,不占cpu资源。 这个是实时改大小,所以速度太慢,希望有人来改改。我是不想弄了,反正又没用什么特别的技术。
提示:拖动的秘密就在filter:alpha(opacity=0)这一句,感兴趣的小伙伴,下面一起跟随编程之家 jb51.cc的小编来看看吧。<br><strong>经测试代码如下:</strong>
  1. <script language="javascript">
  2. /**
  3. * 拉伸拖动iframe框架
  4. *
  5. * @param
  6. * @arrange (512.笔记) jb51.cc
  7. **/
  8. var mouseX = 0;
  9. var mouseY = 0;
  10. var w=5;
  11. function divonmousemove(){
  12. obj1=document.getElementById("a");
  13. obj2=document.getElementById("b");
  14. obj12=document.getElementById("ab");
  15. if (mouseX!==event.x && mouseY!==event.y)obj12.style.cursor='se-resize';
  16. else if (mouseX!==event.x)obj12.style.cursor='e-resize';
  17. else if (mouseY!==event.y)obj12.style.cursor='s-resize';
  18. else obj12.style.cursor='';
  19. if (event.button==1){
  20. obj1.style.width=parseInt(obj1.offsetWidth)+(event.x - mouseX);
  21. mouseX=event.x;
  22. obj1.style.height=parseInt(obj1.offsetHeight)+(event.y - mouseY);
  23. mouseY= event.y;
  24. obj12.style.width=108;
  25. obj12.style.left=obj1.offsetWidth-obj12.offsetWidth/2;
  26. obj12.style.height=obj1.clientHeight;
  27. obj2.style.height=obj1.clientHeight;
  28. obj2.style.left=obj1.clientWidth+w;
  29. obj2.style.width=screen.width-obj1.offsetWidth-w;
  30. }}
  31. function divonmousedown(){
  32. mouseX = event.x;
  33. mouseY = event.y;
  34. }
  35. function divonmouseup(){
  36. obj12.style.left=obj1.offsetWidth;
  37. obj12.style.width=w;
  38. mouseX = 0;
  39. mouseY = 0;}
  40. </script>
  41. <body style='margin:0'>
  42. <iframe zindex=1 id="a" src="http://jb51.cc" style="width:200;height:610;position:absolute;z-index:9 "></iframe>
  43. <div zindex=0 id='ab' onm ousemove='divonmousemove();' onm ouseleave='document.getElementById("ab").style.cursor='';' onm ousedown='divonmousedown();' onm ouseup='divonmouseup();' style='filter:alpha(opacity=0);width:5;height:799;background:#aaffaa;position:absolute;left:200;z-index:100' title='按下鼠标拖动大小'></div>
  44. <iframe zindex=1 id="b" name="ContentFrame" src="http://jb51.cc" style="width:799;height:612;position:absolute;left:205;z-index:10"></iframe>
  45. </body>
  46. </html>

修改一:
  1. <script language="javascript">
  2. /**
  3. * 拉伸拖动iframe框架
  4. *
  5. * @param
  6. * @arrange (512.笔记) jb51.cc
  7. **/
  8. var isResizing=false;
  9. function Resize_mousedown(event,obj){
  10. obj.mouseDownX=event.clientX;
  11. obj.leftTdW=obj.prevIoUsSibling.offsetWidth;
  12. obj.setCapture();
  13. isResizing=true;
  14. }
  15. function Resize_mousemove(event,obj){
  16. if(!isResizing) return ;
  17. var newWidth=obj.leftTdW*1+event.clientX*1-obj.mouseDownX;
  18. if(newWidth>0) obj.prevIoUsSibling.style.width = newWidth;
  19. else obj.prevIoUsSibling.style.width=1;
  20. }
  21. function Resize_mouseup(event,obj){
  22. if(!isResizing) return;
  23. obj.releaseCapture();
  24. isResizing=false;
  25. }
  26. </script>
  27. <body style='margin:0' >
  28. <table style="width:100%;height:100%;" border=0 cellspacing=0 cellpadding=0px >
  29. <tr>
  30. <td style="width:150px;">
  31. <iframe zindex=1 id="a" src="jb51.cc" style="width:100%;height:100%;z-index:9 "></iframe>
  32. </td>
  33. <td style="width:2px;cursor:e-resize;background-color:#cccccc;" onm ousedown="Resize_mousedown(event,this);"
  34. onmouseup="Resize_mouseup(event,this);" onm ousemove="Resize_mousemove(event,this);">
  35. </td>
  36. <td>
  37. <iframe zindex=1 id="b" name="ContentFrame" src="jb51.cc" style="width:100%;height:100%;z-index:10"></iframe>
  38. </td>
  39. </tr>
  40. </table>
  41. </body>

修改二:
  1. <script language="javascript">
  2. /**
  3. * 拉伸拖动iframe框架
  4. *
  5. * @param
  6. * @arrange (512.笔记) jb51.cc
  7. **/
  8. var isResizing=false;
  9. function Resize_mousedown(event,obj){
  10. if(!isResizing) return;
  11. obj.releaseCapture();
  12. isResizing=false;
  13. }
  14. function Resize_setDefault(event,obj){
  15. if(obj.innerText=="<") {
  16. obj.parentNode.prevIoUsSibling.style.width=1;
  17. obj.innerText=">";
  18. }
  19. else{
  20. obj.parentNode.prevIoUsSibling.style.width=150;
  21. obj.innerText="<";
  22. }
  23. event.cancelBubble=true;
  24. }
  25. </script>
  26. <body style='margin:0' >
  27. <table style="width:100%;height:100%;" border=0 cellspacing=0 cellpadding=0px >
  28. <tr>
  29. <td style="width:150px;" >
  30. <iframe zindex=1 id="a" src="jb51.cc" style="width:100%;height:100%;z-index:9 "></iframe>
  31. </td>
  32. <td style="width:3px;cursor:e-resize;background-color:#cccccc;" align="center" valign="middle"
  33. onmousedown="Resize_mousedown(event,this);" onm ouseup="Resize_mouseup(event,this);">
  34. <font style="size:3px;background-color:#eeeeee;cursor:pointer;" onm ousedown="Resize_setDefault(event,this);"><</font>
  35. </td>
  36. <td>
  37. <iframe zindex=1 id="b" name="ContentFrame" src="jb51.cc" style="width:100%;height:100%;z-index:10"></iframe>
  38. </td>
  39. </tr>
  40. </table>
  41. </body>

猜你在找的JavaScript相关文章