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

123
Vistas
shorter way to pause a video if it is fully out of view

I have this code to pause a video if it is fully out of view
it works, but I want to make it shorter
for example, to avoid forEach loop, because this is the only video on page
also - maybe to avoid a separate modify function - but place el.pause() inside the first block of js code
I tried on various ways and getting various errors in console
pls help

<video id='vsingle' src='lorem.mp4' poster='lorem.jpg' controls></video>   

let io = new IntersectionObserver((entries) => {
  entries.forEach(entry => {
    if(!entry.isIntersecting){modify(entry.target);}
  });
});

function modify(el){el.pause();}

$(document).ready(function(){
  io.observe(document.querySelector('#vsingle'));
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You could simplify this code a little by removing the modify function:

let io = new IntersectionObserver((entries) => {
  entries.forEach(entry => {
    if(!entry.isIntersecting){
      entry.target.pause()
    }
  });
});
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