zoukankan
html css js c++ java
JS实现从照片中裁切自已的肖像
代码如下:
<HTML xmlns:v> <BODY> <style> #tbHole td{background:white;filter:alpha(opacity=50);-moz-opacity:.5} #tbHole img{1;height:1;visibility:hidden} v\:*{behavior:url(#default#vml)} </style> <div id=bxHole onselectstart=return(false) ondragstart=return(false) onmousedown=return(false) oncontextmenu=return(false) style="position:absolute;left:0;top:0;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 onmousedown=$('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 onmousedown=$('bxHole').dragStart(event,1) style="cursor:nw-resize;position:absolute;5;height:5;border:1px solid white;background:#BCBCBC"> <img id=bxHoleMove2 src=http://www.5djs.com/images/upload/41.gif onmousedown=$('bxHole').dragStart(event,2) style="cursor:sw-resize;position:absolute;5;height:5;border:1px solid white;background:#BCBCBC"> <img id=bxHoleMove3 src=http://www.5djs.com/images/upload/41.gif onmousedown=$('bxHole').dragStart(event,3) style="cursor:nw-resize;position:absolute;5;height:5;border:1px solid white;background:#BCBCBC"> <img id=bxHoleMove4 src=http://www.5djs.com/images/upload/41.gif onmousedown=$('bxHole').dragStart(event,4) style="cursor:sw-resize;position:absolute;5;height:5;border:1px solid white;background:#BCBCBC"> </div> <div id=bxImgHoleShow style="position:absolute;left:850;top:50;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;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.onmouseup=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.onmousemove=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 全选 提示:你可先修改部分代码,再点运行代码]
青苹果Web应用商店
https://webapp.taobao.com/
PHP/ASP.NET/ASP/UCHOME/DISCUZ! X系列网站开发,详细需求联系
QQ:8511978
查看全文
相关阅读:
烟大课表PC端-不仅仅是浏览器和手机APP
关于51单片机电子时钟精度的问题
第十二周项目4-点、圆的关系
Git on Windows 一些问题
vi 的使用
Git 账户认证的一些问题
[Windows] win7 配置Java开发环境
Velocity 局部定制模板
[Storm] Storm与asm的恩恩怨怨
[Storm] No data flows into bolt
原文地址:https://www.cnblogs.com/Dicky/p/618741.html
最新文章
Shiro第二篇【介绍Shiro、认证流程、自定义realm、自定义realm支持md5】
Shiro第一篇【Shiro的基础知识、回顾URL拦截】
Mybatis第九篇【基于Maven在Idea下Mybatis逆向工程】
Mybatis第八篇【一级缓存、二级缓存、与ehcache整合】
Mybatis第七篇【resultMap、resultType、延迟加载】
Mybatis第六篇【配置文件和映射文件再解读、占位符、主键生成与获取、Mapper代理】
切换输入法默认语言为英文
SpringMVC第七篇【RESTful支持、拦截器】
SpringMVC第六篇【校验、统一处理异常】
SpringMVC第五篇【方法返回值、数据回显、idea下配置虚拟目录、文件上传】
热门文章
SpringMVC第四篇【参数绑定详讲、默认支持参数类型、自定义参数绑定、RequestParam注解】
Maven常见错误以及解决方案【转载】
Maven第四篇【私有仓库、上传jar包、引用私服jar包、上传本地项目到私服】
第十三周项目3-立体类族共有的抽象类
第十三周项目2-形状类族的中的纯虚函数
第十三周项目1-动物这样叫
Windows 上安装 Jekyll
GitHub for Windows一般操作
关于ssh连接主机git连接github失败的问题
不得不爱,Visual Studio Code十大超酷特性
Copyright © 2011-2022 走看看