2014-05-01 3 views
0

을 내가 JCrop가 호출되기 전에 변수를 설정 - 자바 스크립트

을 활용하는 저장소를 만드는 오전 지금 그들은이 필요합니다 캔버스의 크기로 질문 2에 대한 대답 내용에 따라 변경됩니다 jcrop가 설정 한 화면 비율 변화.

질문 4의 사진을 업로드하면이 동작을 볼 수 있습니다. 문제는 내가 이미지를 업로드하고 JCrop을 초기화 한 후 질문 2를 변경하면 완벽하게 잘 작동한다는 것입니다. 그러나 처음 초기화 될 때 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()); 

는로 교체! 내 코드를 살펴볼 시간을 내 주셔서 대단히 감사합니다. 귀하의 제안은 정확히 문제였습니다! 다시 한번 감사드립니다 :) –

관련 문제