Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

204
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda