Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

203
Visualizações
How to extract the returne value of my function JavaScript

I used this function to get the ratio width/height of a photo to assign automatic values of portrait or lanscape:

    var newimage = new Image();
    newimage.src = ImageDir; //Directory of my image
    newimage.onload = function ratio()
{
    var width = this.naturalWidth;
    var height = this.naturalHeight;
    var divi = (width/height);
    return divi.value;
}
alert(divi)

Will return the correct value, but I want to in corporate this code:

if (divi > 1) {
        node.getElementById("myImage"+"-"+nump).dataset.size = ("1600x1200");
    } else {
        node.getElementById("myImage"+"-"+nump).dataset.size = ("1200x1600");
}

I tried someting like this:

var newimage = new Image();
    newimage.src = ImageDir; //Directory of my image
    newimage.onload = function ratio()
{
    var width = this.naturalWidth;
    var height = this.naturalHeight;
    var divi = (width/height);
    if (divi > 1) {
        node.getElementById("myImage"+"-"+nump).dataset.size = ("1600x1200"); //nump is the number of repetitions the While loop as been in (for increments)
    } else {
        node.getElementById("myImage"+"-"+nump).dataset.size = ("1200x1600");
}
}

But the values of if and else won't output... They do if I put them out of the first function. This is all in a While loop, so the divi variable will change everytime.

Can someone help me get that Divi value for my If condition? Thank you!

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda