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

165
Vistas
Adjustment to lazy loading script

This script loads background images upon scrolling to them. I'm interested in having the images loaded after the full document is ready instead, but I'm not sure how i'd modify this script to achieve that.

css

.hiddenbackground {
background-image: none !important;
}

js

<script type="text/javascript">

    document.addEventListener("DOMContentLoaded", function() {
      var lazyBackgrounds = [].slice.call(document.querySelectorAll(".hiddenbackground"));

      if ("IntersectionObserver" in window) {
        let lazyBackgroundObserver = new IntersectionObserver(function(entries, observer) {
          entries.forEach(function(entry) {
            if (entry.isIntersecting) {
              entry.target.classList.remove("hiddenbackground");
              lazyBackgroundObserver.unobserve(entry.target);
            }
          });
        });

        lazyBackgrounds.forEach(function(lazyBackground) {
          lazyBackgroundObserver.observe(lazyBackground);
        });
      }
    });

  </script>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you need a simple script that removes the CSS class .hiddenbackground from all elements that have it as soon as the page loads, you can use something like this:

document.addEventListener('load', () => {
  document.querySelectorAll('.hiddenbackground').forEach(el => {
    el.classList.remove('hiddenbackground');
  });
});

Aside notes
However, instead of removing_the class as soon as the page loads via JavaScript, why do you ship it in the first place? Instead of using JS to remove a class from the DOM, you might (probably) remove it from your HTML entirely before it is delivered to a user.

Alternative "solution" Instead of modifying the JS side of things, how about simply deleting the CSS definition for .hiddenbackground?

.hiddenbackground {
  /* background-image: none !important; */
}

Or just delete it entirely.

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