tags:

views:

89

answers:

1

Hi Does someone know why this just wont work!! i have tried alsorts.

function loadJcrop(widthN, heightN){
    var run = true;
    if( run === true ) {
     alert(  parseInt(Number(widthN) / Number(heightN)) );
     jQuery(function(widthN, heightN) {
      jQuery('#cropbox').Jcrop({
       onChange: showCoords, onSelect: showCoords, aspectRatio: parseInt(Number(widthN) / Number(heightN))
              });    
     });
    }
}

jQuery(window).load(function() {
    loadJcrop(16, 1);
});

the alert returns 16 but nothing!!

and if i put

aspectRatio: 16

it works

any ideas??

+1  A: 

First, I would make the calculations in one spot. Second, I think you're better off Math.round. Most importantly, however, you are using function parameters in your inner function, and I don't think you want to do that (it will unset the variables heightN and widthN).

I would re-write that function as:

function loadJcrop(widthN, heightN){
 // This is much clearer and easier to understand.
 var current = Math.round( Number(widthN) / Number(heightN) );
 var run = true;
 if( run ) { // if you have a variable which is a Boolean, 
          // you should not use '=='
  alert(  current );
  jQuery(function(/* Note the empty parameters */) {
    jQuery('#cropbox').Jcrop({
      onChange: showCoords, onSelect: showCoords, aspectRatio: current)
     });       
  });
 }
}
Christopher W. Allen-Poole
works the same but i see where you are coming from... got a slight problem but i guess there is nothing i can do about that. Dont know if you have ever used jCrop but you can set an aspect ratio. using everything ive written the actual aspect is out slightly. But i think that may be due to the jCrop coding. Thanks.
Phil Jackson