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

233
Vistas
get location of video, on page – JS

I have a video, here with: class="myVideo" and this video has autoplay, but it might take the browser a couple of seconds to load the video so that it can be played and so I want to add a loading screen.

I wrote a script that, on page load, runs every 10 milliseconds and checks if my video is already loaded and when it is, it stops running and it tells me that the video is loaded so that I can then remove the loading screen, that I want to first place over my video.

My Problem:

How can I detect the exact size and position of .myVideo on the page and translate that to .myLoadingScreen? (When the page is loaded.)

This is what I have so far:

document.querySelector(".myLoadingScreen").style.top = document.querySelector(".myVideo").getBoundingClientRect().top + "px";

This seems right, but I tried a bunch of things and I did a lot of testing and I just can't get it to work. – It works very occasionally, but most of the time ".myLoadingScreen" is place somewhere at a pretty random location. – But occasionally it does work.

First I thought it's because the browser may need a little bit of time to draw the video and my script just takes the location of the video too early and so I added a setTimeout, but even a long timeout does not change anything.

I really tried to figure this out, but I have no idea what's going on…

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