1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | // 显示裁剪框 PictureEdit.prototype.showCropBox = function () { this .cropBox.show(); this .btnGroup.show(); this .cropGroup.show(); }; // 隐藏裁剪框 PictureEdit.prototype.hideCropBox = function () { this .cropBox.hide(); this .btnGroup.hide(); this .cropGroup.hide(); this .preImg.cropper( 'destroy' ); }; // 处理上传图片(选择裁剪比例) PictureEdit.prototype.changeCropScale = function () { var that = this ; that.cropGroup.on( 'change' , 'input' , function () { var scale = this .value.split( '/' ); that.preImg.cropper( 'destroy' ); that.preImg.cropper($.extend(that.cropOption, { aspectRatio: scale[0] / scale[1] })); }); }; // 处理上传图片(裁剪,缩放) PictureEdit.prototype.crop = function () { var that = this ; // 取消裁剪 that.cancel(); // 确认裁剪 that.cropBtn.click( function () { that.addPics(); that.hideCropBox(); }); }; // 取消上传图片 PictureEdit.prototype.cancel = function () { var that = this ; that.cancelCropBtn.click( function () { that.hideCropBox(); }); }; // 生成上传图片的key PictureEdit.prototype.getFileKey = function () { var str = '0123456789abcdefghijklmnopqrstuvwxyz' , n = str.length, key = "" , i = 1; while (i < n) { var a = Math.floor(n * Math.random()); key += str.charAt(a); i++; } return key }; // 添加上传的图片 PictureEdit.prototype.addPics = function () { var thumb = $( '<div ><i>x</i></div>' ), key = this .getFileKey(), data = '' ; this .cropImg = this .preImg.cropper( 'getCroppedCanvas' , { width: 200, height: 200 }); data = this .cropImg.toDataURL(); thumb.css( 'backgroundImage' , 'url(' + data + ')' ).attr( 'key' , key); thumb.Before( this .uploadBtnWrap); this .pics[key] = data.split( ',' ).pop(); }; // 删除上传的图片 PictureEdit.prototype.delPics = function () { var that = this ; that.imageWrap.on( 'click' , 'i' , function () { var parent = $( this ).parent( '.item' ), key = parent.attr( 'key' ); parent.remove(); that.pics[key]; }); }; // 获取全部base64数据 PictureEdit.prototype.getPicsData = function () { var arr = []; $.each( this .pics, function (i, n) { arr.push(n); }); return arr.join( ',' ); }; |
特别申明:
本站所有资源都是由网友投稿发布,或转载各大下载站,请自行检测软件的完整性!
本站所有资源仅供学习与参考,请勿用于商业用途,否则产生的一切后果将由您自己承担!
如有侵权请联系我们删除下架,联系方式:lei1294551502@163.com