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

201
Views
Cargue todas las imágenes cuando no se admita el observador de intersección

Estoy usando el observador de intersección para imágenes de carga tardía. ¿Cómo puedo cargar todas las imágenes en navegadores que no admiten el observador de intersecciones?

mi guion=

 const imob = new IntersectionObserver((entries, self) => { entries.forEach(entry => { if (entry.isIntersecting) { llo(entry.target); self.unobserve(entry.target); } }); }); document.querySelectorAll('.lzyp').forEach((pcu) => { imob.observe(pcu); }); const llo = (pcu) => { const img = pcu.querySelector('img'); const sce = pcu.querySelectorAll('source'); sce.forEach((sue) => { sue.srcset = sue.dataset.srcset; sue.removeAttribute('data-srcset'); }); img.src = img.dataset.src; img.removeAttribute('data-src'); }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

  1. ¿Quizás un polyfill para IntersectionObserver ?

  2. Agregar código de respaldo si IntersectionObserver no es compatible.

 if (!('IntersectionObserver' in window) || !('IntersectionObserverEntry' in window) || !('intersectionRatio' in window.IntersectionObserverEntry.prototype) || !('isIntersecting' in window.IntersectionObserverEntry.prototype) ) { // load all images here document.querySelectorAll('.lzyp').forEach( llo ); }

La función Resolver flecha no es compatible con IE:

 // change from this document.querySelectorAll('.lzyp').forEach((pcu) => { imob.observe(pcu); }); // to this document.querySelectorAll('.lzyp').forEach( function(pcu) { imob.observe(pcu); });

juntar:

 function llo(pcu) { const img = pcu.querySelector('img'); const sce = pcu.querySelectorAll('source'); sce.forEach((sue) => { sue.srcset = sue.dataset.srcset; sue.removeAttribute('data-srcset'); }); img.src = img.dataset.src; img.removeAttribute('data-src'); } // IntersectionObserver is not supported if (!('IntersectionObserver' in window) || !('IntersectionObserverEntry' in window) || !('intersectionRatio' in window.IntersectionObserverEntry.prototype) || !('isIntersecting' in window.IntersectionObserverEntry.prototype) ) { // load all images here document.querySelectorAll('.lzyp').forEach( llo ); } else { const imob = new IntersectionObserver( function(entries, self) { entries.forEach( function(entry) { if (entry.isIntersecting) { llo(entry.target); self.unobserve(entry.target); } }); }); document.querySelectorAll('.lzyp').forEach(function(pcu) { imob.observe(pcu); }); }
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!