jq 图片裁剪

1.html

<div class="jcropbox"  style="display: none">
     <img src="" alt="" id="jcropImg"  style="display: none"/>
   <div class="right-img-box">
         <span class="title-text">头像预览</span>
         <div class="imgBigBox" style="width: 186px; height: 186px; overflow: hidden"><img src="" alt="" id="imgBig" /></div>
         <span class="title-text">大头像150*150</span>
         <div class="imgSmallBox" style="width: 24px; height: 24px; overflow: hidden"><img src="" alt="" id="imgSmall"/></div>
         <span class="title-text">小头像24*24</span>
     </div>
     <div class="updateImg default-btn" id="updateImg">确定</div>
</div>

2.js

//jq引用
<script src="/third-party/jquery.Jcrop.min.js"></script>

//使用
var data = {url: 'xxx.jpg'}
var updatePreview = function(c){
  if (parseInt(c.w) > 0){
  $('#imgSmall').css({
  width: Math.round(this.small / c.w * this.boundx) + 'px',
  height: Math.round(this.small/ c.h * this.boundy) + 'px',
   marginLeft: '-' + Math.round(this.small / c.w * c.x) + 'px',
  marginTop: '-' + Math.round(this.small/ c.h * c.y) + 'px'
  });
  $('#imgBig').css({
  width: Math.round(this.big / c.w * this.boundx) + 'px',
  height: Math.round(this.big/ c.h * this.boundy) + 'px',
  marginLeft: '-' + Math.round(this.big / c.w * c.x) + 'px',
  marginTop: '-' + Math.round(this.big/ c.h * c.y) + 'px'
  });
  }
  this.x = c.x;
  this.y = c.y;
  this.w = c.w;
  this.h = c.h;
}
$("#jcropImg").attr("src",data.url);
$("#imgBig").attr("src",data.url);
$("#imgSmall").attr("src",data.url);
$(
'#jcropImg').Jcrop({ aspectRatio:1, //比例 setSelect: [ 0, 0, 2000,2000], //开始默认 boxWidth:200, boxHeight:200, onChange: updatePreview, onSelect: updatePreview },function () { var bounds = this.getBounds(); this.boundx = bounds[0]; this.boundy = bounds[1]; this.small = 24; this.big = 186; });

 

3.这种方式一般用在用户的头像处理 取大图和小图 并保存在node 的相应位置

配合方式

先上传图片:http://www.cnblogs.com/zycbloger/p/6230029.html

前端截图:http://www.cnblogs.com/zycbloger/p/6230095.html

最后node截图:http://www.cnblogs.com/zycbloger/p/6230155.html

转载于:https://www.cnblogs.com/zycbloger/p/6230095.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值