我有3个不同的div与他们的图像。每个div具有不同的宽度和高度。 我对他们都使用jQuery imgAreaSelect。裁剪工作正常。 我的问题是我想在裁剪窗口打开时以初始裁剪开始。 我希望这个最初的作物是给定长宽比的最大可能porportions。jQuery imgAreaSelect
我一起工作的代码是:
var aspectratio1 = $('#cutout_'+cutout_id).height()/$('#cutout_'+cutout_id).width();
aspectratio = "1:" + aspectratio1;
var image_width = $('#CutoutImage').width();
var image_height = $('#CutoutImage').height();
var aspect = 1/aspectratio1 ;
var NewWidth = Math.round(image_height * aspect);
var left = ((image_width - NewWidth)/2);
var right = Math.round(NewWidth + left);
var x1 = left;
var y1 = 0;
var x2 = right;
var y2 = image_height;
$('#CutoutImage').imgAreaSelect({
aspectRatio: aspectratio,
instance: true,
zIndex: 9999,
x1: x1,
y1: y1,
x2: x2,
y2: y2
});
这似乎没有正常工作。任何帮助或见解都非常感谢。
非常感谢您
我们需要关于它不工作的更多细节 - JavaScript控制台中的错误,奇怪的行为,其他?你正在加载jQuery和imgAreaSelect插件是你吗? – Rup
没有javascript错误。是的,我正在加载jquery和imgareaselesct插件。它似乎在大多数时间都有效,但当我使用较小的图像时,作物要么丢失,要么离开左侧,或者初始作物的长宽比关闭,直到作物被移动。其中裁剪移动的比例是正常的 – user583576