0

I want to add loader on my site when I load the site then I set up the SetTimeout for 2 secs then I add the hidden class, but somehow it won't work, any ideas?

const preLoader = document.getElementById('preloader');

function loaderSite() {
  preLoader.classList.add('hidden');
}

window.addEventListener('load', () => {
  setTimeout(loaderSite, 2500);
}, false);
<div class="" id="preloader">
  <div id="loader"></div>
</div>
<div clas="navbar"></div>
Showrin Barua
  • 1,737
  • 1
  • 11
  • 22
Killian Pierce
  • 121
  • 3
  • 12
  • 3
    Does this answer your question? [How to show Page Loading div until the page has finished loading?](https://stackoverflow.com/questions/1853662/how-to-show-page-loading-div-until-the-page-has-finished-loading) –  Jun 03 '21 at 21:19

1 Answers1

0

It's working, brother.

const preLoader = document.getElementById('preloader');

function loaderSite() {
  preLoader.classList.add('hidden');
}

window.addEventListener('load', () => {
  setTimeout(loaderSite, 2500);
}, false);
.hidden {
  display: none;
}
<div class="" id="preloader">
  <div id="loader">Loading</div>
</div>
<div clas="navbar"></div>
Showrin Barua
  • 1,737
  • 1
  • 11
  • 22