我有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