Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

43
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!