dimanche 24 juin 2018

why my if statement alternates with else every time i run the function

So here i made a function from a button to upload images using ajax to show on the canvas but to specify the width and height I use the if statement. I specify if width greater than height the width = 300 and height = 200, if width less than height width = 200 and height = 300.

But i dont know how the if i click the button for first time after refresh my page the if statement is not correct or else sometime it is. And the next following click is alternately. Here my code.

      var image2 = new Image();   
      image2.src = '../img/template/'+e; 
      tmpWidht = parseInt(image2.width);
      tmpHeight = parseInt(image2.height);

      if( tmpWidht > tmpHeight ){
        var imgWidth = 300;
        var imgHeight = 200;
      }else{
        var imgWidth = 200;
        var imgHeight = 300;
      }

Aucun commentaire:

Enregistrer un commentaire