现在jcrop已经可以在触摸屏上使用,我想做一个使用它的Web应用程序。我已经将所有东西都搞定了,但如果我尝试使设计响应式,以便用户在裁剪之前可以看到整个图像(其宽度是屏幕的百分比),则裁剪区域将与用户选择的不同。在调整大小的图像上进行选择的坐标将无法匹配完整大小图像上的坐标。
Jcrop包括解决类似问题的解决方案(处理巨大图像时)使用盒模型或truesize方法,但如果图像的宽度基于百分比而不是像素,则它们都无法工作。
我能想到的唯一解决方案是使用媒体查询调整图像大小,并根据屏幕宽度制作3或4个版本,但我更愿意坚持基于百分比的调整大小,因为它看起来更好。
这是我的jcrop调用:
var jcrop_api, boundx, boundy;
$('#target').Jcrop({
onChange: updatePreview,
onSelect: updatePreview,
aspectRatio: 0.75
},function(){
// Use the API to get the real image size
var bounds = this.getBounds();
boundx = bounds[0];
boundy = bounds[1];
trueSize: [900,600],
// Store the API in the jcrop_api variable
jcrop_api = this;
});
function updatePreview(c){
if (parseInt(c.w) > 0){
var rx = <?echo $width;?> / c.w;
var ry = <?echo $height;?> / c.h;
$('#preview').css({
width: Math.round(rx * boundx) + 'px',
height: Math.round(ry * boundy) + 'px',
marginLeft: '-' + Math.round(rx * c.x) + 'px',
marginTop: '-' + Math.round(ry * c.y) + 'px'
});
}
$('#x').val(c.x);
$('#y').val(c.y);
$('#w').val(c.w);
$('#h').val(c.h);
};
Jcrop
,它就不再对我具有响应性。 - Dex