Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

adding setTimeout to close a preloader

I’m not so good at javascript and I’m trying to add setTimeout to close my preloader after a certain time, but it doesn’t work. Can someone help me? Thank you so much.

document.onreadystatechange = function () {
    var e = document.readyState;
    "interactive" == e
        ? ((document.body.style.overflow = "hidden"), (document.getElementById("contents").style.visibility = "hidden"))
        : "complete" == e &&
          setTimeout(function () {
              document.getElementById("interactive"), (document.body.style.overflow = "auto"), (document.getElementById("load").style.visibility = "hidden"), (document.getElementById("contents").style.visibility = "visible");
              
          },
           1e3);
           setTimeout(e, 3500);
};

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

If I understood correctly what you are trying to achieve , this is what you are looking for.

window.addEventListener('load', () => { // wait to load the page
  setTimeout(() => {
    document.querySelector('.loader').style.display = 'none' // hide the loader after 3.5 seconds
    console.log('loaded')
  }, 3500)
})
<div class="loader">Loading...</div>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading