Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

76
Vistas
How to pass data from multiple function returns to single variable in js/jquery

I have a function, which gets paragraph height, and calculates image height by subtracting 100vh - paragraph height, every time image is loaded.

It results in not satisfying effect, I would like to substract the highest value that this function get.

So what I’m thinking the best approach would be to pass data from multiple loads to single variable, and pick the highest one. Although I’m js beginner and have no idea how to do that. Correct me if I’m wrong.

$(".module img").one("load", function () {
    
    var z = $(this).next('p').height()
    console.log(z)
    $('.module img').css({'height': 'calc(100vh - ' + z + 'px)'})

}).each(function() {
  if(this.complete) {
      //$(this).load(); // For jQuery < 3.0 
       $(this).trigger('load'); // For jQuery >= 3.0 
  }
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Sth like this should do the job:

It's simply storing highest value in variable and use it

let maxHeight = 0;

$(".module img").one("load", function () {
    
    var z = $(this).next('p').height()

    if (z > maxHeight){
      maxHeight = z;
    }

    console.log(z)
    $('.module img').css({'height': 'calc(100vh - ' + maxHeight + 'px)'})

}).each(function() {
  if(this.complete) {
      //$(this).load(); // For jQuery < 3.0 
       $(this).trigger('load'); // For jQuery >= 3.0 
  }
});

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda