2012-03-20 26 views
1

我一直在努力解決這個問題一段時間了。到目前爲止,我找不到任何答案/解決方案,我希望你們中的一位能幫助我。imgAreaSelect +正在改變aspectratio在飛行

情況是這樣的:我使用imgAreaSelect來裁剪圖像。但用戶有可能改變寬高比。這通過輸入寬度和高度(例如100:20)。

您可以在下面找到我的代碼:

var ias = jQuery('#photo').imgAreaSelect({instance:true}); 
ias.setOptions({aspectRatio:'100:20'}); 
ias.update(); 

所以,我有我的imgAreaSelect的實例在var ias。但不知何故,我無法通過SetOptions()更改設置。 我得到的錯誤是:

Uncaught TypeError: Object # has no method 'getOwnPropertyNames'

不過奇怪的是這樣的,如果我做console.dir(ias)我完全看到我對象在控制檯中。其他一切都按照它應該的方式工作裁剪工作完美,我不能通過setOptions()編輯我的選項。

我忘了什麼嗎?

在此先感謝! Steve

回答

0

set setOptions to true。請參閱示例代碼:

var own = $('#crop_img').imgAreaSelect({x1: 0, y1: 0, x2: $('#crop_img').width(), y2: $('#crop_img').height(), 
    handles: true, instance:true, 
    aspectRatio:"{{ $javascript->ratio }}", 
    resizable:true, 
    persistent:true, 
    **setOptions:true**, 
    imageWidth:"{{ $javascript->width }}", 
    imageHeight:"{{ $javascript->height }}", 
+0

請問您可以格式化代碼並添加一些解釋爲什麼這會起作用? – prabugp 2016-03-02 18:58:44

+0

我發現只是嘗試和調試onInit函數。的OnInit:功能(IMG,選擇){ \t \t $( '#ratio_id')上( '變更',函數(){ \t \t \t比= THIS.VALUE; \t \t \t own.setOptions({的aspectRatio。 :ratio}); \t \t \t own.update(); \t \t}); \t}, – 2016-03-05 10:07:48