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 removeChild 障眼法 可能出现的错误
Oct 06 Javascript
灵活应用js调试技巧解决样式问题的步骤分享
Mar 15 Javascript
改变隐藏的input中value值的方法
Mar 19 Javascript
jQuery中next方法用法实例
Apr 24 Javascript
js实现的简洁网页滑动tab菜单效果代码
Aug 24 Javascript
Bootstrap每天必学之按钮(一)
Nov 24 Javascript
JS实现复制内容到剪贴板功能
Feb 05 Javascript
详谈AngularJs 控制器、数据绑定、作用域
Jul 09 Javascript
JS声明对象时属性名加引号与不加引号的问题及解决方法
Feb 16 Javascript
微信小程序实现星级评价效果
Dec 28 Javascript
jquery3和layui冲突导致使用layui.layer.full弹出全屏iframe窗口时高度152px问题
May 12 jQuery
webpack中的模式(mode)使用详解
Feb 20 Javascript
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实现框架(二)
2006/10/09 PHP
php 保留小数点
2009/04/21 PHP
Java中final关键字详解
2015/08/10 PHP
JQuery下关于$.Ready()的分析
2009/12/13 Javascript
由JavaScript技术实现的web小游戏(不含网游)
2010/06/12 Javascript
JQuery datepicker 使用方法
2011/05/20 Javascript
表格单元格交错着色实现思路及代码
2013/04/01 Javascript
js实现网页随机切换背景图片的方法
2014/11/01 Javascript
JavaScript实现列出数组中最长的连续数
2014/12/29 Javascript
JS获取时间的方法
2015/01/21 Javascript
js实现文本框只允许输入数字并限制数字大小的方法
2015/08/19 Javascript
bootstrap轮播图示例代码分享
2017/05/17 Javascript
详解在vue-cli项目中安装node-sass
2017/06/21 Javascript
js实现扫雷小程序的示例代码
2017/09/27 Javascript
Angular @HostBinding()和@HostListener()用法
2018/03/05 Javascript
微信小程序实现顶部导航特效
2019/01/28 Javascript
layui表格内放置图片,并点击放大的实例
2019/09/10 Javascript
Vue+Vuex实现自动登录的知识点详解
2020/03/04 Javascript
[00:33]2016完美“圣”典风云人物:Sccc宣传片
2016/12/03 DOTA
[01:02:34]TFT vs VGJ.T Supermajor 败者组 BO3 第二场 6.5
2018/06/06 DOTA
python计算N天之后日期的方法
2015/03/31 Python
python查找指定具有相同内容文件的方法
2015/06/28 Python
Python判断两个list是否是父子集关系的实例
2018/05/04 Python
Python当中的array数组对象实例详解
2019/06/12 Python
python批量修改xml属性的实现方式
2020/03/05 Python
详解python安装matplotlib库三种失败情况
2020/07/28 Python
Python实现敏感词过滤的4种方法
2020/09/12 Python
法制宣传实施方案
2014/03/13 职场文书
企业承诺书格式范文
2015/04/28 职场文书
母亲去世追悼词
2015/06/23 职场文书
有关西游记的读书笔记
2015/06/25 职场文书
2015年秋季校长开学典礼致辞
2015/07/29 职场文书
经典祝酒词大全
2015/08/12 职场文书
小学英语教学反思范文
2016/02/15 职场文书
MySQL COUNT函数的使用与优化
2021/05/10 MySQL
解决使用了nginx获取IP地址都是127.0.0.1 的问题
2021/09/25 Servers