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

169
Views
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 answers
Answer question

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