1
我對fengyuanchen jQuery Cropper.js v3.0.0有一個小問題。我試圖覆蓋默認的預覽代碼,使其尺寸與原始圖像的顯示尺寸相同。設置fengyuanchen jQuery Cropper.js v3.0.0預覽大小與圖像相同
我目前遇到的問題是,一旦圖像的高度超過了原始圖像的顯示尺寸,預覽會比原始圖像大得多。我寧願它保持在同一高度。
的默認行爲顯示預覽比原始圖像更小:
是我想什麼是使預覽保持在高度相同原始圖像,並且不能超過它:
這裏是我的代碼:
<div class="col col-6">
<img id="image" src=picture.jpg>
</div>
<div class="col col-3">
<div class="preview"></div>
</div>
//css
.preview {
overflow: hidden;
width: 200px;
height: 200px;
}
//JS:
$(function() {
var $preview = $('.preview');
var cropper = $('#image').cropper({
ready: function (e) {
var $clone = $(this).clone().removeClass('cropper-hidden');
$clone.css({
display: 'block',
width: '100%',
minWidth: 0,
minHeight: 0,
maxWidth: 'none',
maxHeight: 'none'
});
$preview.css({
width: '100%',
overflow: 'hidden'//,
//maxHeight: $(this).cropper('getContainerData').height + 'px'
}).html($clone);
},
crop: function(e) {
var imageData = $(this).cropper('getImageData'),
previewAspectRatio = e.width/e.height,
previewWidth = $preview.width(),
previewHeight = previewWidth/previewAspectRatio,
imageScaledRatio = e.width/previewWidth;
//if (previewHeight > $(this).cropper('getContainerData').height) {
//???
//}
$preview.height(previewHeight).find('img').css({
width: imageData.naturalWidth/imageScaledRatio,
height: imageData.naturalHeight/imageScaledRatio,
marginLeft: -e.x/imageScaledRatio,
marginTop: -e.y/imageScaledRatio
});
}
});
});
好吧,我想我已經想通了。星期一我會回答我自己的問題... –