vendredi 3 décembre 2021

Why is this Javascript 'if' statement not working?

I am trying to create an image viewer in javascript. So, there's this function where I am decreasing the size of image when '-' button is pressed or mouse wheel is scrolled downwards. But after the image's height goes below 10px, I can't enlarge it back anymore. So, to tackle that issue, I thought of putting an if statement where it'll check the height of the image and won't decrease the size if it's not above 10px. But, that if statement is not working. And I can't figure out why.

Below is a piece of my code. I tried to put an console.log() to check if it's going into the if statement or not. But, it's not going.

function decrease_image(){
    var img = new Image();
    img = image_viewer_pics[current_viewer_image];
    
    if (img.style.height < "100%"){
        img.style.margin = "auto 0px";
    }

    if (img.style.height > "10px"){
        img.height = img.height / 1.1;
        console.log("greater than 10px");
    }
    
}

Aucun commentaire:

Enregistrer un commentaire