复制代码代码如下:
<html>
<头>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<标题>调整大小</标题>
<样式类型=“文本/css”>
#rRightDown,#rLeftDown,#rLeftUp,#rRightUp,#rRight,#rLeft,#rUp,#rDown{
位置:绝对;背景:#C00;宽度:6px;高度:6px;z-index:5;字体大小:0;}
#rLeftDown,#rRightUp{光标:ne-resize;}
#rRightDown,#rLeftUp{光标:nw-调整大小;}
#rRight,#rLeft{光标:e-调整大小;}
#rUp,#rDown{光标:n-调整大小;}
#rRightDown{ 底部:-3px;右:-3px;}
#rLeftDown{ 底部:-3px;左:-3px;}
#rRightUp{ 顶部:-3px;右:-3px;}
#rLeftUp{ 顶部:-3px;左:-3px;}
#rRight{ 右:-3px;顶部:50%}
#rLeft{ 左:-3px;顶部:50%}
#rUp{ 顶部:-3px;剩余:50%}
#rDown{ 底部:-3px;剩余:50%}
</风格>
</头>
<正文>
<div id='ss' style="height:100px; width:100px; border:1pxsolid #000000;position:absolute; left:200px; top:200px;" >
<div id="rRightDown"> </div>
<div id="rLeftDown"> </div>
<div id="rRightUp"> </div>
<div id="rLeftUp"> </div>
<div id="rRight"> </div>
<div id="rLeft"> </div>
<div id="rUp"> </div>
<div id="rDown"></div>
</div>
<脚本>
var Sys = (函数(ua){
var s = {};
s.IE = ua.match(/msie([/d.]+)/)?true:false;
s.Firefox = ua.match(/firefox//([/d.]+)/)?true:false;
s.Chrome = ua.match(/chrome//([/d.]+)/)?true:false;
s.IE6 = (s.IE&&([/MSIE (/d)/.0/i.exec(navigator.userAgent)][0][1] == 6))?true:false;
s.IE7 = (s.IE&&([/MSIE (/d)/.0/i.exec(navigator.userAgent)][0][1] == 7))?true:false;
s.IE8 = (s.IE&&([/MSIE (/d)/.0/i.exec(navigator.userAgent)][0][1] == 8))?true:false;
返回 s;
})(navigator.userAgent.toLowerCase());
var $ = 函数(id){
返回 document.getElementById(id);
};
var Css = 函数(e,o){
for(var i in o)
e.style[i] = o[i];
};
var 扩展 = 函数(目标,源){
for (源中的 var 属性) {
目的地[属性] = 源[属性];
}
};
var 绑定 = 函数(对象,乐趣){
var args = Array.prototype.slice.call(arguments).slice(2);
返回函数(){
返回 fun.apply(object, args);
}
};
var BindAsEventListener = 函数(对象,乐趣){
var args = Array.prototype.slice.call(arguments).slice(2);
返回函数(事件){
return fun.apply(object, [event || window.event].concat(args));
}
};
var CurrentStyle = 函数(元素){
返回元素.currentStyle || document.defaultView.getComputedStyle(element, null);
};
函数 addListener(元素,e,fn){
element.addEventListener?element.addEventListener(e,fn,false):element.attachEvent("on" + e,fn);
};
函数removeListener(元素,e,fn){
element.removeEventListener?element.removeEventListener(e,fn,false):element.detachEvent("on" + e,fn)
};
var 类 = 函数(属性){
var _class = function(){return (arguments[0] !== null && this.initialize && typeof(this.initialize) == 'function') ? this.initialize.apply(this, 参数) : this;};
_class.prototype = 属性;
返回_class;
};
var 调整大小=新类({
初始化:函数(obj){
这个.obj = obj;
this.resizeelm = null;
this.fun = null; //记录触发什么事件的索引
this.original = []; //记录开始状态的内存
this.width = null;
this.height = null;
this.fR = BindAsEventListener(this,this.resize);
this.fS = 绑定(this,this.stop);
},
设置:函数(榆树,方向){
if(!elm)返回;
this.resizeelm = 榆树;
addListener(this.resizeelm,'mousedown',BindAsEventListener(this, this.start, this[方向]));
返回这个;
},
开始:函数(e,fun){
this.fun = 乐趣;
this.original = [parseInt(CurrentStyle(this.obj).width),parseInt(CurrentStyle(this.obj).height),parseInt(CurrentStyle(this.obj).left),parseInt(CurrentStyle(this.obj).顶部)];
this.width = (this.original[2]||0) + this.original[0];
this.height = (this.original[3]||0) + this.original[1];
addListener(文档,"mousemove",this.fR);
addListener(文档,'mouseup',this.fS);
},
调整大小:函数(e){
this.fun(e);
Sys.IE?(this.resizeelm.onlosecapture=function(){this.fS()}):(this.resizeelm.onblur=function(){this.fS()})
},
停止:函数(){
removeListener(文档, "mousemove", this.fR);
removeListener(文档, "mousemove", this.fS);
窗口.getSelection ? window.getSelection().removeAllRanges() : document.selection.empty();
},
上:函数(e){
this.height>e.clientY?Css(this.obj,{top:e.clientY + "px",height:this.height-e.clientY + "px"}):this.turnDown(e);
},
向下:函数(e){
e.clientY>this.original[3]?Css(this.obj,{top:this.original[3]+'px',height:e.clientY-this.original[3]+'px'}): this.turnUp(e);
},
左:函数(e){
e.clientX<this.width?Css(this.obj,{left:e.clientX +'px',width:this.width-e.clientX + "px"}):this.turnRight(e);
},
右:函数(e){
e.clientX>this.original[2]?Css(this.obj,{left:this.original[2]+'px',width:e.clientX-this.original[2]+"px"}): this.turnLeft(e) ;
},
左上:函数(e){
this.up(e);this.left(e);
},
左下:函数(e){
this.left(e);this.down(e);
},
rightUp:函数(e){
this.up(e);this.right(e);
},
rightDown:函数(e){
this.right(e);this.down(e);
},
关闭:函数(e){
Css(this.obj,{top:this.height+'px',height:e.clientY - this.height + 'px'});
},
翻转:函数(e){
Css(this.obj,{顶部: e.clientY +'px',高度: this.original[3] - e.clientY +'px'});
},
右转:函数(e){
Css(this.obj,{left:this.width+'px',width:e.clientX- this.width +'px'});
},
左转:函数(e){
Css(this.obj,{左:e.clientX +'px',宽度:this.original[2]-e.clientX+'px'});
}
});
窗口.onload = 函数(){
新的调整大小($('ss')).set($('rUp'),'up').set($('rDown'),'down').set($('rLeft'),'left' ).set($('rRight'),'right').set($(' rLeftUp'),'leftUp').set($('rLeftDown'),'leftDown').set($('rRightDown'),'rightDown').set($('rRightUp'),'rightUp') ;
}
</脚本>
</正文>
</html>