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

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

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 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