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

249
Visualizações
javascript math: what is the height of the image

What is the css height of the image if the width is for example: 3px?

original image height is 400px; original image width is 800px;

what I've tried is:

convert the 3px to a percentage of the original image width:

function perwVal(v){
return 100 * v / iow; //img orig width
}

function perhVal(v){
return   v / 100 * ioh; // img original height
}

var imgwidthPerc = perwVal(3);
var imgheightPerc = perhVal(imgwidthPerc);

// not correct the height is off

any help will be appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You get the ratio of the width vs. height:

const ratio = originalWidth / originalHeight;

and then to find the width for a different height:

const newWidth = newHeight * ratio;

In your example:

const originalHeight = 800;
const originalWidth = 400;
const ratio = originalWidth / originalHeight;
const newHeight = 3;
const newWidth = newHeight * ratio;
console.log(newWidth);

But note Sebastian's point that you may not need it, you may be able to use CSS's aspect-ratio.

about 4 years ago · Juan Pablo Isaza Relatório
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