简体   繁体   English

添加 setTimeout 以关闭预加载器

[英]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.我不太擅长 javascript,我正在尝试添加 setTimeout 以在一段时间后关闭我的预加载器,但它不起作用。 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);
};

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM