1.自定义宽高效果
1.html 代码 index.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> <script src="/UploadFiles/2021-04-02/jquery-1.12.4.min.js">2.添加插件代码
(function ($) { $.fn.photoCrop=function (option) { var opt={ img:'', fixedScale:9/5, isHead:null, maxWidth:'1400', maxHeight:'800', callBack:function () {} } opt=$.extend(opt,option); var _this=this; var imgSrc=opt.img "photoCropBox" style="position: fixed;width: 100%;height: 100%;top: 0;left: 0;background: rgba(0,0,0,0.5);z-index: 99999;padding: 20px;">' + '<canvas id="cropCanvas" style="position: absolute;opacity:1;left: 0;top: 0;z-index: 100"></canvas><img id="dataImg" src="/UploadFiles/2021-04-02/'+imgSrc+'">3.绑定代码
$(function () { $('.source').on('click',function () { $(this).photoCrop({ fixedScale:false, isHead:false, callBack:function(url){ $('.target').attr('src',url) }, }); }) })2.宽高比例固定效果
代码:
$(function () { $('.source').on('click',function () { $(this).photoCrop({ fixedScale:5/6, isHead:false, callBack:function(url){ $('.target').attr('src',url) }, }); }) })3.头像裁剪效果
代码:
$(function () { $('.source').on('click',function () { $(this).photoCrop({ fixedScale:1, isHead:true, callBack:function(url){ $('.target').attr('src',url) }, }); }) })以上代码易修改,大家可以自行扩展。希望本文的内容对大家的学习或者工作能带来一定的帮助,同时也希望多多支持!