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

170
Vistas
How to make viewport bigger

I'm trying to make a video play automatically (iframe) when it's in the viewport. The problem now is, that the video needs to be big, so in order for it to be in the viewport, it's almost impossible for a user to scroll to the section, so the video is deadcenter...

I'm wondering how I could solve that, if you have any ideas, please let me know.

I'm thinking about the functions which returns if an element is in the viewport which looks like this:

enter image description here

Maybe I can make the viewport bigger?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Well it's me again. I've solved this with a little "hack".

In my html I added an abslute positioned element which is behind the iframe and has no content. Since this is a very small element, it is faster in the viewport and the video starts playing, eventhough the video isn't fully in the viewport.

Not sure if this was the best solution but it worked for me :)

Html

<div class="js-viewport c-video-slider__viewport"></div>

Css

.c-video-slider__viewport {position: absolute; top 45%;}

JS

var vp = document.querySelector(".js-viewport");
if (this.isInViewport(vp) != false) {...}
isInViewport(el) {
    const rect = el.getBoundingClientRect();
    return (
        rect.top >= 0 &&
        rect.left >= 0 &&
        rect.bottom <=
            (window.innerHeight || document.documentElement.clientHeight) &&
        rect.right <=
            (window.innerWidth || document.documentElement.clientWidth)
    );
}
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