【发布时间】:2018-03-16 21:38:35
【问题描述】:
如何在初始化预览前确定图片的尺寸,只有图片宽度超过200px才开始裁剪?
这里是原始JS:
$('#my_file').on('change', function() {
var file_name = $(this).val();
if(file_name.length > 0) {
addJcrop(this);
}
});
var addJcrop = function(input) {
if ($('#image_prev').data('Jcrop')) {
$('#image_prev').data('Jcrop').destroy();
}
// this will add the src in image_prev as uploaded
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$("#image_prev").attr('src', e.target.result);
var box_width = $('#form-photo').width();
$('#image_prev').Jcrop({
setSelect: [ 175, 100, 400, 300 ],
aspectRatio: 1,
keySupport: false,
boxWidth: box_width
},function(){
var jcrop_api = this;
thumbnail = this.initComponent('Thumbnailer', { width: 326, height: 326 });
});
}
reader.readAsDataURL(input.files[0]);
}
}
【问题讨论】: