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拖拽组件
Jul 28 Javascript
浅析javascript中function 的 length 属性
May 27 Javascript
利用原生JavaScript获取元素样式只是获取而已
Oct 08 Javascript
基于jQuery实现交互体验社会化分享代码附源码下载
Jan 04 Javascript
jQuery头像裁剪工具jcrop用法实例(附演示与demo源码下载)
Jan 22 Javascript
jQuery的each循环用法简单示例
Jun 12 Javascript
js中scrollTop()方法和scroll()方法用法示例
Oct 03 Javascript
es6中的解构赋值、扩展运算符和rest参数使用详解
Sep 28 Javascript
vue 全选与反选的实现方法(无Bug 新手看过来)
Feb 09 Javascript
webstorm+vue初始化项目的方法
Oct 18 Javascript
echarts实现获取datazoom的起始值(包括x轴和y轴)
Jul 20 Javascript
javaScript代码飘红报错看不懂?读完这篇文章再试试
Aug 19 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
thinkphp3.0 模板中函数的使用
2012/11/13 PHP
PHP统计数值数组中出现频率最多的10个数字的方法
2015/04/20 PHP
php常用数组函数实例小结
2016/12/29 PHP
PHP实现QQ、微信和支付宝三合一收款码实例代码
2018/02/19 PHP
php JWT在web端中的使用方法教程
2018/09/06 PHP
PhpStorm配置Xdebug调试的方法步骤
2019/02/02 PHP
js 事件小结 表格区别
2007/08/13 Javascript
一个小型js框架myJSFrame附API使用帮助
2008/06/28 Javascript
动态加载iframe时get请求传递中文参数乱码解决方法
2014/05/07 Javascript
如何用JavaScript定义一个类
2014/09/12 Javascript
完美实现仿QQ空间评论回复特效
2015/05/06 Javascript
基于Arcgis for javascript实现百度地图ABCD marker的效果
2015/09/12 Javascript
JavaScript实现通过select标签跳转网页的方法
2016/09/29 Javascript
jquery封装插件时匿名函数形参和实参的写法解释
2017/02/14 Javascript
nodejs连接mysql数据库简单封装示例-mysql模块
2017/04/10 NodeJs
微信小程序movable view移动图片和双指缩放实例代码
2017/08/08 Javascript
收集前端面试题之url、href、src
2018/03/22 Javascript
layui的layedit富文本赋值方法
2019/09/18 Javascript
Vue 实例中使用$refs的注意事项
2021/01/29 Vue.js
python基础教程之类class定义使用方法
2014/02/20 Python
零基础写python爬虫之神器正则表达式
2014/11/06 Python
Windows下为Python安装Matplotlib模块
2015/11/06 Python
python线程、进程和协程详解
2016/07/19 Python
Python模块的加载讲解
2019/01/15 Python
解决Python中导入自己写的类,被划红线,但不影响执行的问题
2020/07/13 Python
Python3爬虫里关于代理的设置总结
2020/07/30 Python
波兰家具和室内装饰品购物网站:Vivre
2018/04/10 全球购物
比较基础的php面试题及答案-编程题
2012/10/14 面试题
中软Java笔试题
2012/11/11 面试题
求职信内容考虑哪几点
2013/10/05 职场文书
办公室文员工作自我评价
2013/12/01 职场文书
团干部培训方案
2014/06/03 职场文书
JS + HTML 罗盘式时钟的实现
2021/05/21 Javascript
解决Navicat for MySQL 连接 MySQL 报2005错误的问题
2021/05/29 MySQL
Python中常见的反爬机制及其破解方法总结
2021/06/10 Python
vue 自定义的组件绑定点击事件
2022/04/21 Vue.js