@@ -124,8 +124,10 @@ function getMIME(url)
124
124
}
125
125
}
126
126
127
- function cropper(imgSrc,cropperFileE,w,h )
127
+ function cropper(imgSrc,cropperFileE)
128
128
{
129
+ var w = $(cropperFileE).attr('data-w');
130
+ var h = $(cropperFileE).attr('data-h');
129
131
var cropperImg = '<div id="cropping-div"><img id="cropping-img" src="'+imgSrc+'"><\/div>';
130
132
//生成弹层模块
131
133
layer.open({
@@ -193,9 +195,6 @@ function cropper(imgSrc,cropperFileE,w,h)
193
195
194
196
//在input file内容改变的时候触发事件
195
197
$('form').on('change','.cropper-file',function(fileE){
196
- var w = $(this).attr('data-w');
197
- var h = $(this).attr('data-h');
198
-
199
198
//获取input file的files文件数组;
200
199
//这边默认只能选一个,但是存放形式仍然是数组,所以取第一个元素使用[0];
201
200
var file = $(this)[0].files[0];
@@ -208,7 +207,7 @@ function cropper(imgSrc,cropperFileE,w,h)
208
207
//选择所要显示图片的img,要赋值给img的src就是e中target下result里面的base64编码格式的地址
209
208
$(this).nextAll('.cropper-img').attr('src',e.target.result);
210
209
//调取剪切函数(内部包含了一个弹出框)
211
- cropper(e.target.result,$(fileE.target),w,h );
210
+ cropper(e.target.result,$(fileE.target));
212
211
//向后两轮定位到隐藏起来的输入框体
213
212
$(this).nextAll('.cropper-input').val(e.target.result);
214
213
};
@@ -217,9 +216,7 @@ function cropper(imgSrc,cropperFileE,w,h)
217
216
218
217
//点击图片触发弹层
219
218
$('form').on('click','.cropper-img',function(){
220
- var w = $(this).attr('data-w');
221
- var h = $(this).attr('data-h');
222
- cropper($(this).attr('src'),$(this).prevAll('.cropper-file'),w,h);
219
+ cropper($(this).attr('src'),$(this).prevAll('.cropper-file'));
223
220
return false;
224
221
});
225
222
0 commit comments