改变大小控件

小小的封装控件(可改变大小,用法同拖动控件一样)
canResize(可拖动),rlayernum(要改变大小的父元件层数)

None.gif <!--
None.gifAuthor:        Kw.Tsou
None.gifDate:        2005/11/26
None.gifContent:    为页面上的元件提供可改变大小的功能
None.gifUseMark:    在body上behavior此物件,然后在需要改变大小的物件上设置canResize="1"属性即可
None.gif
-->
None.gif
< PUBLIC:COMPONENT >
None.gif    
< PUBLIC:ATTACH  EVENT ="onmousedown"  ONEVENT ="resize_eDown()"   />
None.gif    
< PUBLIC:ATTACH  EVENT ="onmouseup"  ONEVENT ="resize_eUp()"   />
None.gif    
< PUBLIC:ATTACH  EVENT ="onmousemove"  ONEVENT ="resize_eMove()"   />
None.gif    
< PUBLIC:ATTACH  EVENT ="onscroll"  ONEVENT ="resize_eUp()"   />
None.gif    
< PUBLIC:EVENT  ID ="resizeevent"   NAME ="ontagresize" />
None.gif
</ PUBLIC:COMPONENT >
ExpandedBlockStart.gifContractedBlock.gif
< SCRIPT  Language ="JavaScript" > dot.gif
InBlock.gif
InBlock.gif    
var isse = false;
InBlock.gif    
var isw = false;
InBlock.gif    
var iss = false;
InBlock.gif    
var OFFSET = 10;
InBlock.gif    
var MINWIDTH = 50;
InBlock.gif    
var MINHEIGHT = 20;
InBlock.gif    
var resizeObj = null;        //虚线框物件
InBlock.gif
    
ExpandedSubBlockStart.gifContractedSubBlock.gif    
function setResizeObj(el)dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if(el!=null)dot.gif{
InBlock.gif            resizeObj 
= el;
InBlock.gif            resizeObj.isLock 
= true;
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
ExpandedSubBlockStart.gifContractedSubBlock.gif    
function releaseResizeObj()dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if(resizeObj!=null)dot.gif{
InBlock.gif            resizeObj.isLock 
= false;
InBlock.gif            
var evt = createEventObject();
InBlock.gif            evt.src 
= resizeObj;
ExpandedSubBlockStart.gifContractedSubBlock.gif            
try dot.gif{ resizeevent.fire(evt); } catch(e) dot.gif{};
InBlock.gif            resizeObj 
= null;
InBlock.gif            
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
function resize_eMove()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var e = window.event;
InBlock.gif        
var el = e.srcElement;
InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if(resizeObj!=null&&window.event.button=="1")dot.gif{
InBlock.gif            
var ex = e.clientX;
InBlock.gif            
var ey = e.clientY;
InBlock.gif            
var w = resizeObj.offsetWidth + ex - resizeObj.xx;
InBlock.gif            
var h = resizeObj.offsetHeight + ey - resizeObj.yy ;
InBlock.gif            resizeObj.xx 
= ex;
InBlock.gif            resizeObj.yy 
= ey;
InBlock.gif            
if(w<MINWIDTH)w=MINWIDTH;
InBlock.gif            
if(h<MINHEIGHT)h=MINHEIGHT;
InBlock.gif            
if(isse||isw)
InBlock.gif                resizeObj.style.width 
= w;
InBlock.gif            
if(isse||iss)
InBlock.gif                resizeObj.style.height 
= h;
InBlock.gif            window.event.returnValue 
= false;
InBlock.gif            window.event.cancelBubble 
= true;
InBlock.gif            
return false;
InBlock.gif                
ExpandedSubBlockEnd.gif        }

InBlock.gif        
InBlock.gif        
ExpandedSubBlockStart.gifContractedSubBlock.gif        
elsedot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if(el.canResize=="1")dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                
if(el!=null)dot.gif{
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
if(!el.oldcursor)dot.gif{
InBlock.gif                        el.oldcursor 
= el.runtimeStyle.cursor||el.style.cursor;
InBlock.gif                        
if(!el.oldcursor)
InBlock.gif                            el.oldcursor 
= "default";
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    
InBlock.gif                    
var width = el.offsetWidth + el.scrollLeft;
InBlock.gif                    
var height = el.offsetHeight + el.scrollTop;
InBlock.gif                    
var offsetX = e.offsetX;
InBlock.gif                    
var offsetY = e.offsetY;
ExpandedSubBlockStart.gifContractedSubBlock.gif                    
if((width-OFFSET<=offsetX&&offsetX<=width+OFFSET)&&(height-OFFSET<=offsetY&&offsetY<=height+OFFSET))dot.gif{
InBlock.gif                        el.runtimeStyle.cursor 
= "se-resize";
InBlock.gif                        isse 
= true;
InBlock.gif                        isw 
= false;
InBlock.gif                        iss 
= false;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockStart.gifContractedSubBlock.gif                    
else if(width-OFFSET<=offsetX&&offsetX<=width+OFFSET)dot.gif{
InBlock.gif                        el.runtimeStyle.cursor 
= "w-resize";
InBlock.gif                        isse 
= false;
InBlock.gif                        isw 
= true;
InBlock.gif                        iss 
= false;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockStart.gifContractedSubBlock.gif                    
else if(height-OFFSET<=offsetY&&offsetY<=height+OFFSET)dot.gif{
InBlock.gif                        el.runtimeStyle.cursor 
= "s-resize";
InBlock.gif                        isse 
= false;
InBlock.gif                        isw 
= false;
InBlock.gif                        iss 
= true;
ExpandedSubBlockEnd.gif                    }

ExpandedSubBlockStart.gifContractedSubBlock.gif                    
elsedot.gif{
InBlock.gif                        el.runtimeStyle.cursor 
= el.oldcursor;
InBlock.gif                        isse 
= false;
InBlock.gif                        isw 
= false;
InBlock.gif                        iss 
= false;
ExpandedSubBlockEnd.gif                    }

InBlock.gif                    window.event.returnValue 
= false;
InBlock.gif                    window.event.cancelBubble 
= true;
ExpandedSubBlockEnd.gif                }

InBlock.gif                
ExpandedSubBlockEnd.gif            }

InBlock.gif
ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif    
InBlock.gif    
//取得移动对象(如只能拖动标题栏进行移动)
ExpandedSubBlockStart.gifContractedSubBlock.gif
    function getOpreateElement(el)dot.gif{
InBlock.gif        
var ret = el;
InBlock.gif        
var layernum = 0;
InBlock.gif        
if(el.rlayernum)
InBlock.gif            layernum 
= parseInt(el.rlayernum);
InBlock.gif        
for(var i=0;i<layernum;i++)
ExpandedSubBlockStart.gifContractedSubBlock.gif        
dot.gif{
InBlock.gif            ret 
= ret.parentElement;
ExpandedSubBlockEnd.gif        }

InBlock.gif        
return ret;
ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif
InBlock.gif    
InBlock.gif    
function resize_eDown()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        
var e = window.event;
InBlock.gif        
var el = e.srcElement;
ExpandedSubBlockStart.gifContractedSubBlock.gif        
if((el.canResize=="1")&&(isse||isw||iss))dot.gif{
InBlock.gif            el 
= getOpreateElement(el);
ExpandedSubBlockStart.gifContractedSubBlock.gif            
if(el!=null)dot.gif{        
InBlock.gif                setResizeObj(el);
InBlock.gif                resizeObj.xx 
= e.clientX;
InBlock.gif                resizeObj.yy 
= e.clientY;
InBlock.gif                window.status 
= "按住鼠标左键拖动可改变大小";
InBlock.gif                window.event.returnValue 
= false;
InBlock.gif                window.event.cancelBubble 
= true;
ExpandedSubBlockEnd.gif            }

ExpandedSubBlockEnd.gif        }

ExpandedSubBlockEnd.gif    }

InBlock.gif
InBlock.gif    
function resize_eUp()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
dot.gif{
InBlock.gif        releaseResizeObj();
InBlock.gif        window.status 
= "Done";
ExpandedSubBlockEnd.gif    }

InBlock.gif
ExpandedBlockEnd.gif
None.gif
</ SCRIPT >
None.gif
None.gif



None.gif < html >
None.gif
< head >
None.gif
< title > 什么都可以拖动,也可改变大小 </ title >
ExpandedBlockStart.gifContractedBlock.gif
< style > dot.gif
ExpandedSubBlockStart.gifContractedSubBlock.gifbody,div,td,font
{dot.gif}{font:menu;}
ExpandedSubBlockStart.gifContractedSubBlock.gifdiv,td
{dot.gif}{text-align:center}
None.gif
</ style >
None.gif
</ head >
None.gif
< body  style ="margin:0px" >
None.gif
< div  ontagmove ="window.status=' left:' + window.event.src.offsetLeft + ' top:' + window.event.src.offsetTop"  style ="margin:3px;position:absolute;overflow:hidden;behavior:url(BlogMoveAble.htc) url(BlogResizeAble.htc);border:1px solid gray;width:90%;height:90%;background-color:#efefef" >
None.gif    
< div  canResize ="1"   canMove  = "1"  style ="background-color:gray;border:1px solid red;cursor:move;top:20px;left:20px;position:absolute;width:100px;height:100px;" >
None.gif        这是一个div(移动右边和下面,可改变大小哟)
None.gif    
</ div >
None.gif    
< div   canResize ="1"   style ="background-color:#e1e1e1;border:1px solid blue;;top:120px;left:120px;position:absolute;width:180px;height:120px;" >
None.gif        
< div  style ="height:30px;border:1px solid white;background-color:white;color:black;cursor:move"  canMove ="1"  layernum ="1" > 只有标题可以拖动 </ div >
None.gif        这是一个div(可改变大小哟)
None.gif    
</ div >
None.gif    
< table  canResize ="1"  border ="1"  bordercolor ="green"  style ="width:50%;height:50%;position:absolute"  ID ="Table1" >
None.gif        
< tr >
None.gif            
< td  canMove ="1"  layernum ="3"  colspan ="2"  style ="cursor:move;background-color:blue;color:white" > 这是表格的标题行(也可改变大小) </ td >
None.gif        
</ tr >
None.gif        
< tr >
None.gif            
< td > 1 </ td >
None.gif            
< td  canResize ="1"  rlayernum ="3" > 2 </ td >
None.gif        
</ tr >
None.gif        
< tr >
None.gif            
< td  canResize ="1"  rlayernum ="3" > 3 </ td >
None.gif            
< td  canResize ="1"  rlayernum ="3" > 4 </ td >
None.gif        
</ tr >
None.gif    
</ table >
None.gif
</ div >
None.gif
</ body >
None.gif
</ html >
None.gif


预览
testresize.htm

下载
resizeble.rar

转载于:https://www.cnblogs.com/cheatlove/articles/405419.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值