2014-05-01 84 views
0

我創建一個店,它利用JCrop設置一個變量之前它被稱爲 - 的Javascript

現在的寬高比jcrop設置將取決於他們回答什麼問題2作爲畫布的尺寸需要改變更改。

您可以通過上傳問題4下的照片來查看此問題。我擁有的問題是,如果更改問題2之後,此工作將非常順利,因爲我上傳了圖像並初始化了JCrop。但是,第一次初始化時,它將使用JCrop默認設置的平方縱橫比(1)。

我怎樣才能讓它使用問題2默認設置的寬高比?

$('select[name=size]').click(function() { 
    getPrice(); 
    }); 

$('select[name=size]').change(function() { 
    getPrice($(this).val()); 
}); 
//custom function to change aspect ratio depending on answer on question 2 
function getPrice(aspectRatioStr) { 
    var parts = aspectRatioStr.split('x'), 
     num = parseInt(parts[0]), 
     denom = parseInt(parts[1]), 
     newAspectRatio = num/denom; 
    if (!jcrop_api) return; 
    jcrop_api.setOptions({ 
     aspectRatio: newAspectRatio 
    }); 
    jcrop_api.focus(); 
} 

      // standard jcrop initialization 
      $('#preview').Jcrop({ 
       minSize: [32, 32], // min crop size 
       aspectRatio : 1, // keep aspect ratio 1:1 
       bgFade: true, // use fade effect 
       bgOpacity: .3, // fade opacity 
       onChange: updateInfo, 
       onSelect: updateInfo, 
       onRelease: clearInfo, 
       boxWidth: 765 
      }, function(){ 

       // use the Jcrop API to get the real image size 
       var bounds = this.getBounds(); 
       boundx = bounds[0]; 
       boundy = bounds[1]; 

       // Store the Jcrop API in the jcrop_api variable 
       jcrop_api = this; 

      getPrice($('#name').val()); 
      }); 
     }; 
    }; 

回答

1

你的問題是在這裏:

getPrice($('select[name=size]').val()); 
+0

喜Sahbeewah:

getPrice($('#name').val()); 

將其替換!非常感謝您花時間查看我的代碼,您的建議正是問題所在!再次感謝 :) –

相關問題