複製程式碼如下:
<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?
},
停止:函數(){
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 = 函數(){
new Resize($('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>