js实现拉伸拖动iframe的具体代码


Posted in Javascript onAugust 03, 2013

左边iframe放树目录,右边的iframe放index页。拖鼠标同时控制2个iframe的宽高。
期待有人能改进。
操作方法:鼠标指到2个iframe中间,可以水平拖,纵向拖(控制高度)
缺点:CSDN页面放开鼠标后才改大小,不占CPU资源。 这个是实时改大小,所以速度太慢,希望有人来改改。我是不想弄了,反正又没用什么特别的技术。
提示:拖动的秘密就在filter:alpha(opacity=0)这一句

 <html>
<script language="javascript"> 
 var mouseX = 0; 
 var mouseY = 0;
 var w=5; 
 function divonmousemove(){ 
 obj1=document.getElementById("a");
 obj2=document.getElementById("b");
 obj12=document.getElementById("ab");
 if (mouseX!==event.x && mouseY!==event.y)obj12.style.cursor='se-resize'; 
 else if (mouseX!==event.x)obj12.style.cursor='e-resize'; 
 else if (mouseY!==event.y)obj12.style.cursor='s-resize'; 
 else obj12.style.cursor=''; 
 if (event.button==1){ 
 obj1.style.width=parseInt(obj1.offsetWidth)+(event.x - mouseX); 
 mouseX=event.x;
 obj1.style.height=parseInt(obj1.offsetHeight)+(event.y - mouseY); 
 mouseY= event.y; 
 obj12.style.width=108;
 obj12.style.left=obj1.offsetWidth-obj12.offsetWidth/2;
 obj12.style.height=obj1.clientHeight;
 obj2.style.height=obj1.clientHeight;
 obj2.style.left=obj1.clientWidth+w;
 obj2.style.width=screen.width-obj1.offsetWidth-w;
 }} 
function divonmousedown(){   
 mouseX = event.x; 
 mouseY = event.y;
 } 
function divonmouseup(){ 
 obj12.style.left=obj1.offsetWidth;
 obj12.style.width=w;
 mouseX = 0; 
 mouseY = 0;} 
 </script> 
 <body style='margin:0'>
 <iframe zindex=1 id="a" src="https://3water.com/Tree/tree.htm" style="width:200;height:610;position:absolute;z-index:9 "></iframe>
 <div zindex=0 id='ab' onmousemove='divonmousemove();' onmouseleave='document.getElementById("ab").style.cursor='';' 
 onmousedown='divonmousedown();' onmouseup='divonmouseup();' 
 style='filter:alpha(opacity=0);width:5;height:799;background:#aaffaa;position:absolute;left:200;z-index:100' title='按下鼠标拖动大小'></div>  
 <iframe zindex=1 id="b" name="ContentFrame" src="https://3water.com/index.htm" style="width:799;height:612;position:absolute;left:205;z-index:10"></iframe>
 </body>
  </html>

修改一:
<script language="javascript"> 
var isResizing=false;
function Resize_mousedown(event,obj){
obj.mouseDownX=event.clientX;
obj.leftTdW=obj.previousSibling.offsetWidth;
obj.setCapture();
isResizing=true;
}
function Resize_mousemove(event,obj){
if(!isResizing) return ;
var newWidth=obj.leftTdW*1+event.clientX*1-obj.mouseDownX;
if(newWidth>0) obj.previousSibling.style.width = newWidth;
else obj.previousSibling.style.width=1;
}
function Resize_mouseup(event,obj){
if(!isResizing) return;
obj.releaseCapture();
isResizing=false;
}
< /script> 
< body style='margin:0' >
< table style="width:100%;height:100%;" border=0 cellspacing=0 cellpadding=0px >
< tr>
< td style="width:150px;">
< iframe zindex=1 id="a" src="https://3water.com/Tree/tree.htm" style="width:100%;height:100%;z-index:9 "></iframe>
< /td>
< td style="width:2px;cursor:e-resize;background-color:#cccccc;" onmousedown="Resize_mousedown(event,this);" 
onmouseup="Resize_mouseup(event,this);" onmousemove="Resize_mousemove(event,this);">
< /td>
< td>
< iframe zindex=1 id="b" name="ContentFrame" src="https://3water.com/index.htm" style="width:100%;height:100%;z-index:10"></iframe>
< /td>
< /tr>
< /table>
< /body>

修改二:
<script language="javascript"> 
var isResizing=false;
function Resize_mousedown(event,obj){
obj.mouseDownX=event.clientX;
obj.leftTdW=obj.previousSibling.offsetWidth;
obj.setCapture();
isResizing=true;
}
function Resize_mousemove(event,obj){
if(!isResizing) return ;
var newWidth=obj.leftTdW*1+event.clientX*1-obj.mouseDownX;
if(newWidth>0) obj.previousSibling.style.width = newWidth;
else obj.previousSibling.style.width=1;
}
function Resize_mouseup(event,obj){
if(!isResizing) return;
obj.releaseCapture();
isResizing=false;
}
function Resize_setDefault(event,obj){
if(obj.innerText=="<") {
obj.parentNode.previousSibling.style.width=1;
obj.innerText=">";
}
else{
obj.parentNode.previousSibling.style.width=150;
obj.innerText="<";
}
event.cancelBubble=true;
}
< /script> 
< body style='margin:0' >
< table style="width:100%;height:100%;" border=0 cellspacing=0 cellpadding=0px >
< tr>
< td style="width:150px;" >
< iframe zindex=1 id="a" src="https://3water.com/Tree/tree.htm" style="width:100%;height:100%;z-index:9 "></iframe>
< /td>
< td style="width:3px;cursor:e-resize;background-color:#cccccc;" align="center" valign="middle"
onmousedown="Resize_mousedown(event,this);" onmouseup="Resize_mouseup(event,this);" onmousemove="Resize_mousemove(event,this);">
<font style="size:3px;background-color:#eeeeee;cursor:pointer;" onmousedown="Resize_setDefault(event,this);"><</font>
< /td>
< td>
< iframe zindex=1 id="b" name="ContentFrame" src="https://3water.com/index.htm" style="width:100%;height:100%;z-index:10"></iframe>
< /td>
< /tr>
< /table>
< /body>
Javascript 相关文章推荐
js克隆对象、数组的常用方法介绍
Sep 26 Javascript
JavaScript判断前缀、后缀是否是空格的方法
Apr 15 Javascript
JavaScript保存并运算页面中数字类型变量的写法
Jul 06 Javascript
js性能优化技巧
Nov 29 Javascript
AngularJS 使用 UI Router 实现表单向导
Jan 29 Javascript
快速掌握Node.js环境的安装与运行方法
Feb 16 Javascript
jQuery 检查某个元素在页面上是否存在实例代码
Oct 27 Javascript
js实现无缝滚动图
Feb 22 Javascript
vue实现全选、反选功能
Nov 17 Javascript
Vue学习之常用指令实例详解
Jan 06 Javascript
JS实现横向轮播图(中级版)
Jan 18 Javascript
jquery插件实现搜索历史
Apr 24 jQuery
js判断输入是否为数字的具体实例
Aug 03 #Javascript
js replace 与replaceall实例用法详解
Aug 03 #Javascript
jquery动态加载js三种方法实例
Aug 03 #Javascript
js innerHTML 改变div内容的方法
Aug 03 #Javascript
JS代码判断IE6,IE7,IE8,IE9的函数代码
Aug 02 #Javascript
JS自定义功能函数实现动态添加网址参数修改网址参数值
Aug 02 #Javascript
jQuery function的正确书写方法
Aug 02 #Javascript
You might like
php简单对象与数组的转换函数代码(php多层数组和对象的转换)
2011/05/18 PHP
Yii框架中 find findAll 查找出制定的字段的方法对比
2014/09/10 PHP
php获取远程文件的内容和大小
2015/11/03 PHP
PHP定义字符串的四种方式详解
2018/02/06 PHP
TP5框架实现一次选择多张图片并预览的方法示例
2020/04/04 PHP
Javascript 函数对象的多重身份
2009/06/28 Javascript
jquery scrollTop方法根据滚动像素显示隐藏顶部导航条
2013/05/27 Javascript
使用javascript实现页面定时跳转总结篇
2013/09/21 Javascript
关闭页面时window.location事件未执行的原因分析及解决方案
2014/09/01 Javascript
Javascript中arguments对象详解
2014/10/22 Javascript
基于jQuery实现复选框的全选 全不选 反选功能
2014/11/24 Javascript
浅谈javascript 函数表达式和函数声明的区别
2016/01/05 Javascript
基于d3.js实现实时刷新的折线图
2016/08/03 Javascript
JavaScript微信定位功能实现方法
2016/11/29 Javascript
jQuery中绑定事件bind() on() live() one()的异同
2017/02/23 Javascript
详解Vue源码学习之双向绑定
2019/04/10 Javascript
jquery 时间戳转日期过程详解
2019/10/12 jQuery
微信小程序实现吸顶特效
2020/01/08 Javascript
vue.js this.$router.push获取不到params参数问题
2020/03/03 Javascript
JavaScript快速调试的两个技巧
2020/11/04 Javascript
浅谈Python 对象内存占用
2016/07/15 Python
Python生成器定义与简单用法实例分析
2018/04/30 Python
pycharm远程开发项目的实现步骤
2019/01/20 Python
Python中zip()函数的简单用法举例
2019/09/02 Python
Python获取二维数组的行列数的2种方法
2020/02/11 Python
浅谈keras中自定义二分类任务评价指标metrics的方法以及代码
2020/06/11 Python
python的launcher用法知识点总结
2020/08/07 Python
Bonami斯洛伐克:购买家具和家居饰品
2019/07/02 全球购物
RIP版本1跟版本2的区别
2013/12/30 面试题
Linux操作面试题
2012/05/16 面试题
新学期班主任寄语
2014/01/18 职场文书
道路建设实施方案
2014/03/18 职场文书
幼儿园中班教师寄语
2014/04/03 职场文书
个人租房协议书样本
2014/10/01 职场文书
班干部学习委员竞选稿
2015/11/20 职场文书
详解Mysq MVCC多版本的并发控制
2022/04/29 MySQL