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

96
Vistas
JS clientWidth returning 0 sometimes but working other times

I'm writing a program to change the positions of some subtitles. The user uploads a video, gets a thumbnail from the video, and then the editor shows up. A lot of the time, the clientWidth or clientHeight for the thumbnail just doesn't work and it breaks the range sliders. If you refresh though, it sometimes starts working again. I have no idea what the problem is, some help would be much appreciated.

    example.style.left = width.value;
thumbWidth = thumb.clientWidth - example.clientWidth;
thumbHeight = thumb.clientHeight - example.clientHeight;
width.setAttribute('max', thumbWidth);
console.log(thumb.clientWidth);
width.setAttribute('value', thumbWidth / 2);
subWidth();
height.setAttribute('max', thumbHeight);
height.setAttribute('value', thumbHeight / 2);
subHeight();
width.style.width = thumb.clientWidth + 'px';
console.log(thumb.clientWidth);
height.style.width = thumb.clientHeight + 'px';
editor.style.width = thumb.clientWidth = 'px';
editor.style.height = thumb.clientHeight + 'px';

Here is the fiddle.

Btw, I am aware the vertical slider is very hardcoded, but I will fix it later.

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