博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JS实现从照片中裁切自已的肖像
阅读量:4499 次
发布时间:2019-06-08

本文共 4476 字,大约阅读时间需要 14 分钟。

代码如下:
<HTML xmlns:v> <BODY> <style> #tbHole td{background:white;filter:alpha(opacity=50);-moz-opacity:.5} #tbHole img{width:1;height:1;visibility:hidden} v\:*{behavior:url(#default#vml)} </style> <div id=bxHole onselectstart=return(false) οndragstart=return(false) οnmοusedοwn=return(false) οncοntextmenu=return(false) style="position:absolute;left:0;top:0;width:800;height:600;border:1px solid #808080;background:url(http://album.sina.com.cn/pic/40db9aaa02000eh1)"> <table id=tbHole cellpadding=0 cellspacing=0 width=100% height=100% style=position:absolute> <tr height=158><td width=243><img></td><td width=120><img></td><td><img></td></tr> <tr height=140> <td><img></td> <td οnmοusedοwn=$('bxHole').dragStart(event,0) style="background:transparent;filter:;-moz-opacity:1;cursor:move;border:1px solid white !important"><img></td> <td><img></td> </tr> <tr><td><img></td><td><img></td><td><img></td></tr> </table> <img id=bxHoleMove1 src=http://www.5djs.com/images/upload/41.gif οnmοusedοwn=$('bxHole').dragStart(event,1) style="cursor:nw-resize;position:absolute;width:5;height:5;border:1px solid white;background:#BCBCBC"> <img id=bxHoleMove2 src=http://www.5djs.com/images/upload/41.gif οnmοusedοwn=$('bxHole').dragStart(event,2) style="cursor:sw-resize;position:absolute;width:5;height:5;border:1px solid white;background:#BCBCBC"> <img id=bxHoleMove3 src=http://www.5djs.com/images/upload/41.gif οnmοusedοwn=$('bxHole').dragStart(event,3) style="cursor:nw-resize;position:absolute;width:5;height:5;border:1px solid white;background:#BCBCBC"> <img id=bxHoleMove4 src=http://www.5djs.com/images/upload/41.gif οnmοusedοwn=$('bxHole').dragStart(event,4) style="cursor:sw-resize;position:absolute;width:5;height:5;border:1px solid white;background:#BCBCBC"> </div> <div id=bxImgHoleShow style="position:absolute;left:850;top:50;width:120;height:140;border:1px solid #808080;overflow:hidden"></div> </BODY> </html> <script> function $(obj){ return typeof(obj)=="object"?"obj":document.getElementById(obj) } bxHole_ini() function bxHole_ini(){ var bx=$("bxHole"),tb=$("tbHole") $("bxImgHoleShow").innerHTML="<"+(document.all?"v:image":"img")+" id=imgHoleShow src='http://album.sina.com.cn/pic/40db9aaa02000eh1' style='position:absolute;left:0;top:0;width:800;height:600' />" bx.w0=tb.rows[0].cells[1].offsetWidth bx.h0=tb.rows[1].offsetHeight bx.w_img=$("imgHoleShow").offsetWidth bx.h_img=$("imgHoleShow").offsetHeight bx.dragStart=function(e,dragType){ bx.dragType=dragType bx.px=tb.rows[0].cells[0].offsetWidth bx.py=tb.rows[0].offsetHeight bx.pw=tb.rows[0].cells[1].offsetWidth bx.ph=tb.rows[1].offsetHeight bx.sx=e.screenX bx.sy=e.screenY } bx.οnmοuseup=function(){ if(bx.dragType==null) return var w=tb.rows[0].cells[1].offsetWidth,h=tb.rows[1].offsetHeight bx.dragType=null if(w/h>bx.w0/bx.h0) tb.rows[0].cells[1].style.width=h*bx.w0/bx.h0 else tb.rows[1].style.height=w*bx.h0/bx.w0 bx.setTip() } bx.οnmοusemοve=function(e){ var x,y,w,h if(bx.dragType==null) return if(e==null) e=event x=Math.max(bx.px+e.screenX-bx.sx,1) y=Math.max(bx.py+e.screenY-bx.sy,1) w=Math.min(bx.pw+e.screenX-bx.sx,tb.offsetWidth-bx.px-1) h=Math.min(bx.ph+e.screenY-bx.sy,tb.offsetHeight-bx.py-1) if(bx.dragType==0){ x=Math.min(x,tb.offsetWidth-bx.pw-1) y=Math.min(y,tb.offsetHeight-bx.ph-1) w=bx.pw h=bx.ph } if(bx.dragType==1||bx.dragType==4) w=bx.pw+bx.px-x if(bx.dragType==1||bx.dragType==2) h=bx.ph+bx.py-y if(bx.dragType==2||bx.dragType==3) x=bx.px if(bx.dragType==3||bx.dragType==4) y=bx.py w=Math.max(w,bx.w0/2) h=Math.max(h,bx.h0/2) if(bx.dragType==1||bx.dragType==4) x=bx.pw+bx.px-w if(bx.dragType==1||bx.dragType==2) y=bx.ph+bx.py-h tb.rows[0].cells[0].style.width=x tb.rows[0].cells[1].style.width=w tb.rows[0].style.height=y tb.rows[1].style.height=h $("bxHole").setTip() } bx.setTip=function(){ var x=tb.rows[0].cells[0].offsetWidth,y=tb.rows[0].offsetHeight,w=tb.rows[0].cells[1].offsetWidth,h=tb.rows[1].offsetHeight var img=$("imgHoleShow"),per $("bxHoleMove1").style.left=$("bxHoleMove4").style.left=x-3 $("bxHoleMove1").style.top=$("bxHoleMove2").style.top=y-3 $("bxHoleMove2").style.left=$("bxHoleMove3").style.left=x+w-4 $("bxHoleMove3").style.top=$("bxHoleMove4").style.top=y+h-4 if(w/h>bx.w0/bx.h0) w=h*bx.w0/bx.h0 else h=w*bx.h0/bx.w0 per=bx.h0/h img.style.width=per*bx.w_img img.style.height=per*bx.h_img img.style.left=-x*per img.style.top=-y*per } bx.setTip() } </script>
[Ctrl+A 全选 提示:你可先修改部分代码,再点运行代码]

转载于:https://www.cnblogs.com/Dicky/archive/2007/01/12/618741.html

你可能感兴趣的文章
[开源]jquery-ajax-cache:快速优化页面ajax请求,使用localStorage缓存请求
查看>>
Android Sqite数据库 <7>
查看>>
利用Excel导入数据到SAP C4C
查看>>
.NET WebApi使用Swagger
查看>>
Python装饰器实现类Java注解功能
查看>>
django二次开发对接FastDFS
查看>>
【linux-查阅文件】more & less
查看>>
ASP.NET使用FCKEditor_2.6.6与FCKeditor.Net_2.6.3配置(转载)
查看>>
POJ3264 Balanced Lineup
查看>>
Go Walk教程 - 流程控制( switch)
查看>>
JDK中NIO
查看>>
Foobar2000–panel stack splitter
查看>>
设置button图片和文字
查看>>
web前端升级之路
查看>>
Openframework在VS2010中的配置
查看>>
发生死锁怎么办
查看>>
webpack使用时可能出现的问题
查看>>
zh-cn、en-us、zh-tw等表示语言(文化)代码与国家地区对照表(最全的各国地区对照表)...
查看>>
C++ STL 之 函数对象适配器
查看>>
hdu1276(士兵队列训练问题) java集合水过
查看>>