How to set the time of the loader?

Viewed 162

how can i set the time of the loader in this scenario? it works perfectly fine but it was so quick and i tried the inspect element and Network then disable cache and the fast 3G option i just wanna ask if how to set it in like 5 seconds timer

js

window.addEventListener("load",function () {
    const loader = document.querySelector(".loader");
    loader.className += " hidden"; // class hidden loader
});

html

<div class="loader">
  <img src="img/Preloader.gif" alt="loading.."/>
</div>
2 Answers

replace your javascript with this

setTimeout(function() { 
  const loader = document.querySelector(".loader");
  loader.hidden = true;
}, 5000);

replacing this javascript will do the trick

setTimeout(function() { 
  const loader = document.querySelector(".loader");
  loader.className += " hidden";
}, 5000);
Related