javascript

位置:IT落伍者 >> javascript >> 浏览文章

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


发布日期:2021年11月23日
 
js实现拉伸拖动iframe的具体代码
这篇文章介绍了js实现拉伸拖动iframe的具体代码有需要的朋友可以参考一下

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

复制代码 代码如下:
<html>
<script language="javascript">
var mouseX = ;
var mouseY = ;
var w=;
function divonmousemove(){
obj=documentgetElementById("a");
obj=documentgetElementById("b");
obj=documentgetElementById("ab");
if (mouseX!==eventx && mouseY!==eventy)objstylecursor=seresize;
else if (mouseX!==eventx)objstylecursor=eresize;
else if (mouseY!==eventy)objstylecursor=sresize;
else objstylecursor=;
if (eventbutton==){
objstylewidth=parseInt(objoffsetWidth)+(eventx mouseX);
mouseX=eventx;
objstyleheight=parseInt(objoffsetHeight)+(eventy mouseY);
mouseY= eventy;
objstylewidth=;
objstyleleft=objoffsetWidthobjoffsetWidth/;
objstyleheight=objclientHeight;
objstyleheight=objclientHeight;
objstyleleft=objclientWidth+w;
objstylewidth=screenwidthobjoffsetWidthw;
}}
function divonmousedown(){
mouseX = eventx;
mouseY = eventy;
}
function divonmouseup(){
objstyleleft=objoffsetWidth;
objstylewidth=w;
mouseX = ;
mouseY = ;}
</script>
<body style=margin:>
<iframe zindex= id="a" src=":;height:;position:absolute;zindex: "></iframe>
<div zindex= id=ab onmousemove=divonmousemove(); onmouseleave=documentgetElementById("ab")stylecursor=;
onmousedown=divonmousedown(); onmouseup=divonmouseup();
style=filter:alpha(opacity=);width:;height:;background:#aaffaa;position:absolute;left:;zindex: title=按下鼠标拖动大小></div>
<iframe zindex= id="b" name="ContentFrame" src=":;height:;position:absolute;left:;zindex:"></iframe>
</body>
</html>


修改一

复制代码 代码如下:
<script language="javascript">
var isResizing=false;
function Resize_mousedown(eventobj){
objmouseDownX=eventclientX;
objleftTdW=objpreviousSiblingoffsetWidth;
objsetCapture();
isResizing=true;
}
function Resize_mousemove(eventobj){
if(!isResizing) return ;
var newWidth=objleftTdW*+eventclientX*objmouseDownX;
if(newWidth>) objpreviousSiblingstylewidth = newWidth;
else objpreviousSiblingstylewidth=;
}
function Resize_mouseup(eventobj){
if(!isResizing) return;
objreleaseCapture();
isResizing=false;
}
< /script>
< body style=margin: >
< table style="width:%;height:%;" border= cellspacing= cellpadding=px >
< tr>
< td style="width:px;">
< iframe zindex= id="a" src=":%;height:%;zindex: "></iframe>
< /td>
< td style="width:px;cursor:eresize;backgroundcolor:#cccccc;" onmousedown="Resize_mousedown(eventthis);"
onmouseup="Resize_mouseup(eventthis);" onmousemove="Resize_mousemove(eventthis);">
< /td>
< td>
< iframe zindex= id="b" name="ContentFrame" src=":%;height:%;zindex:"></iframe>
< /td>
< /tr>
< /table>
< /body>


修改二

复制代码 代码如下:


<script language="javascript">
var isResizing=false;
function Resize_mousedown(eventobj){
objmouseDownX=eventclientX;
objleftTdW=objpreviousSiblingoffsetWidth;
objsetCapture();
isResizing=true;
}
function Resize_mousemove(eventobj){
if(!isResizing) return ;
var newWidth=objleftTdW*+eventclientX*objmouseDownX;
if(newWidth>) objpreviousSiblingstylewidth = newWidth;
else objpreviousSiblingstylewidth=;
}
function Resize_mouseup(eventobj){
if(!isResizing) return;
objreleaseCapture();
isResizing=false;
}
function Resize_setDefault(eventobj){
if(objinnerText=="<") {
objparentNodepreviousSiblingstylewidth=;
objinnerText=">";
}
else{
objparentNodepreviousSiblingstylewidth=;
objinnerText="<";
}
eventcancelBubble=true;
}
< /script>
< body style=margin: >
< table style="width:%;height:%;" border= cellspacing= cellpadding=px >
< tr>
< td style="width:px;" >
< iframe zindex= id="a" src=":%;height:%;zindex: "></iframe>
< /td>
< td style="width:px;cursor:eresize;backgroundcolor:#cccccc;" align="center" valign="middle"
onmousedown="Resize_mousedown(eventthis);" onmouseup="Resize_mouseup(eventthis);" onmousemove="Resize_mousemove(eventthis);">
<font style="size:px;backgroundcolor:#eeeeee;cursor:pointer;" onmousedown="Resize_setDefault(eventthis);"><</font>
< /td>
< td>
< iframe zindex= id="b" name="ContentFrame" src=":%;height:%;zindex:"></iframe>
< /td>
< /tr>
< /table>
< /body>

上一篇:JS getAttribute和setAttribute(取得和设置属性)的使用介绍

下一篇:如何使用Javascript正则表达式来格式化XML内容