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

44
Vistas
Multiple html video elements iOS issue

I'm currently working on this web app: https://nowe.menu/nowe-menu

The problem is that videos work's perfectly normal on all devices except the iOS. iOS tend to not show every single one - some of them a just not displayed.

I was trying alread to use some lazyload javascript libraries for videos - but it doesn't work either.

Do you guys have some ideas how to make it work?

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

0

I've found a solution to this.

If you're lazy loading videos - you have to unload them if they are out of viewport. It's strange but iphone got like an limited amount of movies that can be loaded at the same time.

I've tested it even with iPhone 6 and it works!

So here is the code:

document.addEventListener("DOMContentLoaded", function() {


 var lazyVideos = [].slice.call(document.querySelectorAll("video.lazy"));
    const options = {
          rootMargin: "500px"
        };



 if ("IntersectionObserver" in window) {
  
var lazyVideoObserver = new IntersectionObserver(function(entries, observer) {
  entries.forEach(function(video) {
    if (video.isIntersecting) {
      for (var source in video.target.children) {
        var videoSource = video.target.children[source];
        if (typeof videoSource.tagName === "string" && videoSource.tagName === "SOURCE") {
          videoSource.src = videoSource.dataset.src;
        }
      }

      video.target.load();
    } else {
        for (var source in video.target.children) {
            var videoSource = video.target.children[source];
            if (typeof videoSource.tagName === "string" && videoSource.tagName === "SOURCE") {
              videoSource.src = '';
            }
          }
          video.target.load();
    }
  });
}, options);

lazyVideos.forEach(function(lazyVideo) {
  lazyVideoObserver.observe(lazyVideo);
});
  }
});

As you can see i'm loading videos in the if statement (when they are visible), and unloading them in else statement (when they are not visible) and then they're loaded once again when they visible again.

Als in the options i've setted rootmargin to 500px - so loading it's only visible when you're fast scrolling.

That's how it works :) Now you can have million videos on one page.

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