Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,购买链接:点击进入购买VIP会员
JAVA高级面试进阶视频教程Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程

Go语言视频零基础入门到精通

Java架构师3期(课件+源码)

Java开发全终端实战租房项目视频教程

SpringBoot2.X入门到高级使用教程

大数据培训第六期全套视频教程

深度学习(CNN RNN GAN)算法原理

Java亿级流量电商系统视频教程

互联网架构师视频教程

年薪50万Spark2.0从入门到精通

年薪50万!人工智能学习路线教程

年薪50万!大数据从入门到精通学习路线年薪50万!机器学习入门到精通视频教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程 MySQL入门到精通教程
查看: 751|回复: 0

跨浏览器可8方向拖拽剪裁框

[复制链接]

该用户从未签到

发表于 2011-10-29 08:25:13 | 显示全部楼层 |阅读模式
Xhtml代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
<html xmlns="http://www.w3.org/1999/xhtml">  
<head>  
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  
<title>Untitled Document</title>  
<style type="text/css">  
* { padding:0; margin:0; }   
body { overflow: hidden; height:800px; }   
#clipArea { width :100px; height:100px; border: dashed 1px #ccc; position: absolute; cursor:move;}   
#clipArea b { position:absolute; height:6px; width:6px; overflow:hidden; display:block; background:#FFF; border: 1px solid #000; background:#eee; }   
#canvasContainer { height:400px; width:600px; border:solid 1px red; position:relative; overflow:hidden; right: 20px; float: right; margin-right: 20px; top: 100px; }   
</style>  
</head>  
  
<body>  
<div id="canvasWrapper">  
    <div id="canvasContainer"></div>  
</div>  
<script type="text/javascript">  
void function(e,g){var f,d,c,a,h;f=document;a=f.getElementsByTagName("body")[0];h=f.getElementById("canvasContainer");d=function(){var i=arguments.callee;i.prototype={type{}).toString,slice:([]).slice,is:function(j){return this.type.call(j).slice(8,-1)},each:function(l,o){var k,m=0,j=l.length,n=j===g&&({}).toString.call(l).slice(8,-1)==="Object";if(n){for(k in l){if(o.call(l[k],k,l[k])===false){break}}}else{for(;m<j;){if(o.call(l[m],m,l[m++])===false){break}}}},toArray:function(j){return this.slice.call(j)},getHtmlElement:function(j){!this.element&&(this.element={});!this.element[j]&&(this.element[j]=f.createElement(j));return this.element[j].cloneNode(true)},getEvent:function(j){return j||e.event},getTarget:function(j){return j.srcElement||j.target},stopEvent:function(j){j=this.getEvent(j);(j.returnValue||j.preventDefault)&&(j.returnValue=false||j.preventDefault());(j.cancelBubble||j.stopPropagation)&&(j.cancelBubble=false||j.stopPropagation())},getClinetRect:function(j){var l=j.getBoundingClientRect(),k=(k={left:l.left,right:l.right,top:l.top,bottom:l.bottom,height:(l.height?l.height:(l.bottom-l.top)),width:(l.width?l.width:(l.right-l.left))});return k},addEvent:function(n,m,l,k){var j=arguments.callee;n.attachEvent&&(j=function(q,p,o){q.attachEvent("on"+p,o)}).apply(this,arguments);n.addEventListener&&(j=function(q,p,o){q.addEventListener(p,o,k||false)}).apply(this,arguments);n["on"+m]&&(j=function(q,p,o){q["on"+p]=function(){o()}}).apply(this,arguments)},removeEvent:function(n,m,l,k){var j=arguments.callee;n.detachEvent&&(j=function(q,p,o){q.detachEvent("on"+p,o)}).apply(this,arguments);n.removeEventListener&&(j=function(q,p,o){q.removeEventListener(p,o,k||false)}).apply(this,arguments);n["on"+m]&&(j=function(q,p,o){q["on"+p]=null}).apply(this,arguments)},currentStyle:function(k,l){var j=null;return g!==k.currentStyle?k.currentStyle[l]:document.defaultView.getComputedStyle(k,null)[l]}};if(e===this||"indicator" in this){return new i}}();var b=function(){var i=arguments.callee,j=d,l=this,k=6,m=null;if(!l instanceof i){return new i()}m={TL:{css:"top:0;left:0;cursor:nw-resize",size:function(n){m.CL.size(n);m.TC.size(n)}},TC:{css:"top:0;left:48%;cursor:n-resize",size:function(n){l.correctY(l.hanlderInfo._down-n.clientY,l.hanlderInfo._mxTH);l.correctTop()}},TR:{css:"right:0;top:0;cursor:ne-resize",size:function(n){m.CR.size(n);m.TC.size(n)}},CL:{css:"top:48%;left:0;cursor:w-resize",size:function(n){l.correctX(l.hanlderInfo._right-n.clientX,l.hanlderInfo._mxLW);l.correctLeft()}},CR:{css:"top:48%;right:0px;cursor:e-resize",size:function(n){l.correctX(n.clientX-l.hanlderInfo._left,l.hanlderInfo._mxRW)}},BL:{css:"bottom:0;left:0;cursor:sw-resize",size:function(n){m.CL.size(n);m.BC.size(n)}},BC:{css:"bottom:0;left:48%;cursor:s-resize",size:function(n){l.correctY(n.clientY-l.hanlderInfo._top,l.hanlderInfo._mxDH)}},BR:{css:"bottom:0;right:0px;cursor:se-resize",size:function(n){m.CR.size(n);m.BC.size(n)}}};l.area=null;!l.activity&&(ii.prototype.constructor=i),ii.fn=i.prototype,ii.fn.constructor=i;i.fn.activity=function(){var o=null,n=[];l.data&&(l.Data=null);if(l.area===null){l.area=j.getHtmlElement("div");l.area.style.visibility="hidden";l.area.id="clipArea";h.appendChild(l.area);n=["TL","TC","TR","CL","CR","BL","BC","BR"];j.each(Array(8),function(q,p){o=j.getHtmlElement("b");o.id=n[q];o.fn=m[n[q]];j.addEvent(o,"mousedown",l.mousemoveCheckThreshold,false);l.area.appendChild(o);l.setHanldPosition(o,l.area,n[q])});j.addEvent(l.area,"mousedown",l.mousemoveCheckThreshold,false);l.area.style.visibility="visible"}};i.fn.setHanldPosition=function(u,n,t){var o=n.offsetWidth,w=n.offsetHeight,r=(o-k),q=Math.floor((o-k)/2),v=(w-k),s=Math.floor((o-k)/2);u.style.cssText=m[t].css};i.fn.mousemoveCheckThreshold=function(p){p=j.getEvent(p);var o=j.getTarget(p),q=[],n=p.type;while(o&&o.nodeType!==1){oo=o.parentNode}({mousedown:function(r){r=j.getEvent(r);j.stopEvent(r);f.currentTarget=o;l.pos=j.getClinetRect(o);l.origin=[r.clientX-l.pos.left,r.clientY-l.pos.top];o.nodeName.toLowerCase()==="b"&&l.checkHandler(r);j.addEvent(f,"mouseup",l.mousemoveCheckThreshold,false);j.addEvent(f,"mousemove",l.mousemoveCheckThreshold,false)},mousemove:function(s){s=j.getEvent(s);var r=f.currentTarget,t=j.getClinetRect(r.parentNode);r.nodeName.toLowerCase()==="b"?l.handlerMove.call(r,s,t):l.areaMove.call(r,s,t);j.stopEvent(s)},mouseup:function(s){s=j.getEvent(s);var r=j.getTarget(s);if(r.nodeName.toLowerCase()!=="b"){try{r.style.cursor="move"}catch(s){}}j.removeEvent(f,"mousemove",l.mousemoveCheckThreshold,false);j.removeEvent(f,"mouseup",l.mousemoveCheckThreshold,false);ll.pos=l.origin=null;delete l.hanlderInfo;j.stopEvent(s)}})[p.type](p)};i.fn.checkHandler=function(q){q=j.getEvent(q);var p=j.getTarget(q),n=p.parentNode,o=j.getClinetRect(n);!l.hanlderInfo&&(l.hanlderInfo={});l.hanlderInfo.mxT=0;l.hanlderInfo.mxL=0;l.hanlderInfo.mxR=n.parentNode.clientWidth;l.hanlderInfo.mxB=n.parentNode.clientHeight;l.hanlderInfo.mxR=Math.max(l.hanlderInfo.mxR,l.hanlderInfo.mxL+40);l.hanlderInfo.mxB=Math.max(l.hanlderInfo.mxB,l.hanlderInfo.mxT+40);l.hanlderInfo.width=n.clientWidth;l.hanlderInfo.height=n.clientHeight;l.hanlderInfo.left=n.offsetLeft;l.hanlderInfo.top=n.offsetTop;l.hanlderInfo._left=o.left;l.hanlderInfo._right=o.right;l.hanlderInfo._top=o.top;l.hanlderInfo._down=o.bottom;ll.hanlderInfo._fixLeft=l.hanlderInfo.width+l.hanlderInfo.left;ll.hanlderInfo._fixTop=l.hanlderInfo.height+l.hanlderInfo.top;ll.hanlderInfo._mxRW=l.hanlderInfo.mxR-l.hanlderInfo.left;ll.hanlderInfo._mxDH=l.hanlderInfo.mxB-l.hanlderInfo.top;l.hanlderInfo._mxTH=Math.max(l.hanlderInfo._fixTop-l.hanlderInfo.mxT,0);l.hanlderInfo._mxLW=Math.max(l.hanlderInfo._fixLeft-l.hanlderInfo.mxL,0)};i.fn.correctX=function(n,o){n=l.correctWidth(n,o);l.hanlderInfo.width=n};i.fn.correctY=function(n,o){n=l.correctHeight(n,o);l.hanlderInfo.height=n};i.fn.correctWidth=function(n,o){n=Math.min(o,n);n=Math.max(n,80,0);return n};i.fn.correctHeight=function(n,o){n=Math.min(o,n);n=Math.max(n,80,0);return n};i.fn.correctTop=function(){ll.hanlderInfo.top=l.hanlderInfo._fixTop-l.hanlderInfo.height};i.fn.correctLeft=function(){ll.hanlderInfo.left=l.hanlderInfo._fixLeft-l.hanlderInfo.width};i.fn.handlerMove=function(n){n=j.getEvent(n);var o=this.id;this.fn.size(n);l.resize();j.stopEvent(n)};i.fn.resize=function(n){var o=l.area;o.style.cssText="width:"+l.hanlderInfo.width+"px;height:"+l.hanlderInfo.height+"px;top:"+l.hanlderInfo.top+"px;left:"+l.hanlderInfo.left+"px"},i.fn.areaMove=function(p){var q=[p.clientX,p.clientY],n=this.parentNode,r,o=j.getClinetRect(n);r=[Math.max(p.clientX-o.left-l.origin[0],0),Math.max(p.clientY-o.top-l.origin[1],0)];r=[Math.min(n.clientWidth-this.offsetWidth,r[0]),Math.min(n.clientHeight-this.offsetHeight,r[1])];this.style.top=r[1]+"px";this.style.left=r[0]+"px"};i.fn.removeArea=function(){try{l.area.parentNode.removeChild(l.area),l.area=null}catch(n){}};i.fn.getData=function(){var n=j.getClinetRect(l.area.parentNode);return l.area?j.getClinetRect(l.area):-1}};new b().activity()}(window);   
</script>  
</body>  
</html>  

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<style type="text/css">
* { padding:0; margin:0; }
body { overflow: hidden; height:800px; }
#clipArea { width :100px; height:100px; border: dashed 1px #ccc; position: absolute; cursor:move;}
#clipArea b { position:absolute; height:6px; width:6px; overflow:hidden; display:block; background:#FFF; border: 1px solid #000; background:#eee; }
#canvasContainer { height:400px; width:600px; border:solid 1px red; position:relative; overflow:hidden; right: 20px; float: right; margin-right: 20px; top: 100px; }
</style>
</head>

<body>
<div id="canvasWrapper">
    <div id="canvasContainer"></div>
</div>
<script type="text/javascript">
void function(e,g){var f,d,c,a,h;f=document;a=f.getElementsByTagName("body")[0];h=f.getElementById("canvasContainer");d=function(){var i=arguments.callee;i.prototype={type:({}).toString,slice:([]).slice,is:function(j){return this.type.call(j).slice(8,-1)},each:function(l,o){var k,m=0,j=l.length,n=j===g&&({}).toString.call(l).slice(8,-1)==="Object";if(n){for(k in l){if(o.call(l[k],k,l[k])===false){break}}}else{for(;m<j;){if(o.call(l[m],m,l[m++])===false){break}}}},toArray:function(j){return this.slice.call(j)},getHtmlElement:function(j){!this.element&&(this.element={});!this.element[j]&&(this.element[j]=f.createElement(j));return this.element[j].cloneNode(true)},getEvent:function(j){return j||e.event},getTarget:function(j){return j.srcElement||j.target},stopEvent:function(j){j=this.getEvent(j);(j.returnValue||j.preventDefault)&&(j.returnValue=false||j.preventDefault());(j.cancelBubble||j.stopPropagation)&&(j.cancelBubble=false||j.stopPropagation())},getClinetRect:function(j){var l=j.getBoundingClientRect(),k=(k={left:l.left,right:l.right,top:l.top,bottom:l.bottom,height:(l.height?l.height:(l.bottom-l.top)),width:(l.width?l.width:(l.right-l.left))});return k},addEvent:function(n,m,l,k){var j=arguments.callee;n.attachEvent&&(j=function(q,p,o){q.attachEvent("on"+p,o)}).apply(this,arguments);n.addEventListener&&(j=function(q,p,o){q.addEventListener(p,o,k||false)}).apply(this,arguments);n["on"+m]&&(j=function(q,p,o){q["on"+p]=function(){o()}}).apply(this,arguments)},removeEvent:function(n,m,l,k){var j=arguments.callee;n.detachEvent&&(j=function(q,p,o){q.detachEvent("on"+p,o)}).apply(this,arguments);n.removeEventListener&&(j=function(q,p,o){q.removeEventListener(p,o,k||false)}).apply(this,arguments);n["on"+m]&&(j=function(q,p,o){q["on"+p]=null}).apply(this,arguments)},currentStyle:function(k,l){var j=null;return g!==k.currentStyle?k.currentStyle[l]:document.defaultView.getComputedStyle(k,null)[l]}};if(e===this||"indicator" in this){return new i}}();var b=function(){var i=arguments.callee,j=d,l=this,k=6,m=null;if(!l instanceof i){return new i()}m={TL:{css:"top:0;left:0;cursor:nw-resize",size:function(n){m.CL.size(n);m.TC.size(n)}},TC:{css:"top:0;left:48%;cursor:n-resize",size:function(n){l.correctY(l.hanlderInfo._down-n.clientY,l.hanlderInfo._mxTH);l.correctTop()}},TR:{css:"right:0;top:0;cursor:ne-resize",size:function(n){m.CR.size(n);m.TC.size(n)}},CL:{css:"top:48%;left:0;cursor:w-resize",size:function(n){l.correctX(l.hanlderInfo._right-n.clientX,l.hanlderInfo._mxLW);l.correctLeft()}},CR:{css:"top:48%;right:0px;cursor:e-resize",size:function(n){l.correctX(n.clientX-l.hanlderInfo._left,l.hanlderInfo._mxRW)}},BL:{css:"bottom:0;left:0;cursor:sw-resize",size:function(n){m.CL.size(n);m.BC.size(n)}},BC:{css:"bottom:0;left:48%;cursor:s-resize",size:function(n){l.correctY(n.clientY-l.hanlderInfo._top,l.hanlderInfo._mxDH)}},BR:{css:"bottom:0;right:0px;cursor:se-resize",size:function(n){m.CR.size(n);m.BC.size(n)}}};l.area=null;!l.activity&&(i.prototype.constructor=i),i.fn=i.prototype,i.fn.constructor=i;i.fn.activity=function(){var o=null,n=[];l.data&&(l.Data=null);if(l.area===null){l.area=j.getHtmlElement("div");l.area.style.visibility="hidden";l.area.id="clipArea";h.appendChild(l.area);n=["TL","TC","TR","CL","CR","BL","BC","BR"];j.each(Array(8),function(q,p){o=j.getHtmlElement("b");o.id=n[q];o.fn=m[n[q]];j.addEvent(o,"mousedown",l.mousemoveCheckThreshold,false);l.area.appendChild(o);l.setHanldPosition(o,l.area,n[q])});j.addEvent(l.area,"mousedown",l.mousemoveCheckThreshold,false);l.area.style.visibility="visible"}};i.fn.setHanldPosition=function(u,n,t){var o=n.offsetWidth,w=n.offsetHeight,r=(o-k),q=Math.floor((o-k)/2),v=(w-k),s=Math.floor((o-k)/2);u.style.cssText=m[t].css};i.fn.mousemoveCheckThreshold=function(p){p=j.getEvent(p);var o=j.getTarget(p),q=[],n=p.type;while(o&&o.nodeType!==1){o=o.parentNode}({mousedown:function(r){r=j.getEvent(r);j.stopEvent(r);f.currentTarget=o;l.pos=j.getClinetRect(o);l.origin=[r.clientX-l.pos.left,r.clientY-l.pos.top];o.nodeName.toLowerCase()==="b"&&l.checkHandler(r);j.addEvent(f,"mouseup",l.mousemoveCheckThreshold,false);j.addEvent(f,"mousemove",l.mousemoveCheckThreshold,false)},mousemove:function(s){s=j.getEvent(s);var r=f.currentTarget,t=j.getClinetRect(r.parentNode);r.nodeName.toLowerCase()==="b"?l.handlerMove.call(r,s,t):l.areaMove.call(r,s,t);j.stopEvent(s)},mouseup:function(s){s=j.getEvent(s);var r=j.getTarget(s);if(r.nodeName.toLowerCase()!=="b"){try{r.style.cursor="move"}catch(s){}}j.removeEvent(f,"mousemove",l.mousemoveCheckThreshold,false);j.removeEvent(f,"mouseup",l.mousemoveCheckThreshold,false);l.pos=l.origin=null;delete l.hanlderInfo;j.stopEvent(s)}})[p.type](p)};i.fn.checkHandler=function(q){q=j.getEvent(q);var p=j.getTarget(q),n=p.parentNode,o=j.getClinetRect(n);!l.hanlderInfo&&(l.hanlderInfo={});l.hanlderInfo.mxT=0;l.hanlderInfo.mxL=0;l.hanlderInfo.mxR=n.parentNode.clientWidth;l.hanlderInfo.mxB=n.parentNode.clientHeight;l.hanlderInfo.mxR=Math.max(l.hanlderInfo.mxR,l.hanlderInfo.mxL+40);l.hanlderInfo.mxB=Math.max(l.hanlderInfo.mxB,l.hanlderInfo.mxT+40);l.hanlderInfo.width=n.clientWidth;l.hanlderInfo.height=n.clientHeight;l.hanlderInfo.left=n.offsetLeft;l.hanlderInfo.top=n.offsetTop;l.hanlderInfo._left=o.left;l.hanlderInfo._right=o.right;l.hanlderInfo._top=o.top;l.hanlderInfo._down=o.bottom;l.hanlderInfo._fixLeft=l.hanlderInfo.width+l.hanlderInfo.left;l.hanlderInfo._fixTop=l.hanlderInfo.height+l.hanlderInfo.top;l.hanlderInfo._mxRW=l.hanlderInfo.mxR-l.hanlderInfo.left;l.hanlderInfo._mxDH=l.hanlderInfo.mxB-l.hanlderInfo.top;l.hanlderInfo._mxTH=Math.max(l.hanlderInfo._fixTop-l.hanlderInfo.mxT,0);l.hanlderInfo._mxLW=Math.max(l.hanlderInfo._fixLeft-l.hanlderInfo.mxL,0)};i.fn.correctX=function(n,o){n=l.correctWidth(n,o);l.hanlderInfo.width=n};i.fn.correctY=function(n,o){n=l.correctHeight(n,o);l.hanlderInfo.height=n};i.fn.correctWidth=function(n,o){n=Math.min(o,n);n=Math.max(n,80,0);return n};i.fn.correctHeight=function(n,o){n=Math.min(o,n);n=Math.max(n,80,0);return n};i.fn.correctTop=function(){l.hanlderInfo.top=l.hanlderInfo._fixTop-l.hanlderInfo.height};i.fn.correctLeft=function(){l.hanlderInfo.left=l.hanlderInfo._fixLeft-l.hanlderInfo.width};i.fn.handlerMove=function(n){n=j.getEvent(n);var o=this.id;this.fn.size(n);l.resize();j.stopEvent(n)};i.fn.resize=function(n){var o=l.area;o.style.cssText="width:"+l.hanlderInfo.width+"px;height:"+l.hanlderInfo.height+"px;top:"+l.hanlderInfo.top+"px;left:"+l.hanlderInfo.left+"px"},i.fn.areaMove=function(p){var q=[p.clientX,p.clientY],n=this.parentNode,r,o=j.getClinetRect(n);r=[Math.max(p.clientX-o.left-l.origin[0],0),Math.max(p.clientY-o.top-l.origin[1],0)];r=[Math.min(n.clientWidth-this.offsetWidth,r[0]),Math.min(n.clientHeight-this.offsetHeight,r[1])];this.style.top=r[1]+"px";this.style.left=r[0]+"px"};i.fn.removeArea=function(){try{l.area.parentNode.removeChild(l.area),l.area=null}catch(n){}};i.fn.getData=function(){var n=j.getClinetRect(l.area.parentNode);return l.area?j.getClinetRect(l.area):-1}};new b().activity()}(window);
</script>
</body>
</html>



大小: 130.7 KB
clip.zip (2.8 KB)
下载次数: 26
查看图片附件
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|手机版|Java学习者论坛 ( 声明:本站资料整理自互联网,用于Java学习者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

GMT+8, 2025-1-8 13:09 , Processed in 0.293672 second(s), 36 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表