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

134
Vistas
Background gif removes from lazy picture with placeholder before that picture is loaded
<a class="background-gif" href="#">
     <picture>
          <img class="lazy-pic" src="img/white-placeholder.png" data-src="img/certificates/2.png">
     </picture>
</a>

img tag has a placeholder and a link has a class "background-gif" that adds loading gif as a background. When I scroll to image, I get data-attribute and put it into src. I need to add "loaded" class to link when picture from data-attribute is loaded and loading background gif will be removed.

   const container = '.background-gif' // it's for example only))
   const lazyPic = container.querySelector('.lazy-pic');
   lazyPic.setAttribute("src",lazyPic.getAttribute('data-src'));
   lazyPic.addEventListener("load", (e) => {
      container.classList.add("loaded");
   })

I've tried to use onLoad event on img, but if it has a placeholder, event fires before picture is loaded. If i remove src placeholder it will cause mistakes in validator)) So, what can I do? The idea to put loading gif as a placeholder is not convenitent - I have a lot of pictures with different fixed sizes, gif should to be same size everywhere.

about 4 years ago · Juan Pablo Isaza
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