【发布时间】:2018-04-14 16:37:46
【问题描述】:
我正在使用带有引导模式的 Croppie,例如 this,但我在浏览器控制台中收到以下错误,这意味着当我单击“裁剪”按钮时,错误如下: ReferenceError:outWHeight 未定义 这是我的 Js 代码(您可以在 CodePen 链接中找到完整的代码):
var $uploadCrop,
tempFilename,
rawImg,
imageId;
function readFile(input) {
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('.upload-demo').addClass('ready');
$('#cropImagePop').modal('show');
rawImg = e.target.result;
}
reader.readAsDataURL(input.files[0]);
}
else {
swal("Sorry - you're browser doesn't support the FileReader API");
}
}
$uploadCrop = $('#upload-demo').croppie({
viewport: {
width: 250,
height: 250,
},
enforceBoundary: false,
enableExif: true
});
$('#cropImagePop').on('shown.bs.modal', function(){
// alert('Shown pop');
$uploadCrop.croppie('bind', {
url: rawImg
}).then(function(){
console.log('jQuery bind complete');
});
});
$('.item-img').on('change', function () { imageId = $(this).data('id'); tempFilename = $(this).val();
$('#cancelCropBtn').data('id', imageId); readFile(this); });
$('#cropImageBtn').on('click', function (ev) {
$uploadCrop.croppie('result', {
type: 'base64',
format: 'jpeg',
size: {width: 1000, height: 1000}
}).then(function (resp) {
$('#item-img-output').attr('src', resp);
$('#cropImagePop').modal('hide');
});
});
【问题讨论】:
-
我无法重现错误
-
@CarstenLøvboAndersen 错误不在 codepen 中。当我在我的网站上使用代码时,出现错误 ReferenceError: outWHeight is not defined
-
我没有对代码做任何改动!
-
它必须与您拥有的其他代码有关,因为您没有在 sn-p 中使用
outWHeight -
@CarstenLøvboAndersen 我测试了错误。我删除了其他库,但失败了。