简体   繁体   English

假装预加载器屏幕

[英]Faking preloader screen

I make a preloader page using valid tutorials for my webpage,我使用有效的网页教程制作了一个预加载页面,
similar to https://codepen.io/bommell/pen/OPaMmj .类似于https://codepen.io/bommell/pen/OPaMmj the problem is I want to make this preloader work somehow fake, without using any heavy contents pics nor videos (iframe .....) In other words, I want to make this preloader a default screen before my actual project, so in js file, I use setTimeout and clearTimeout but it doesn't work, what should I do?问题是我想让这个预加载器以某种方式工作,而不使用任何大量内容图片或视频(iframe .....)换句话说,我想让这个预加载器成为我实际项目之前的默认屏幕,所以在 js 中文件,我使用 setTimeout 和 clearTimeout 但它不起作用,我该怎么办?
the preloader works properly whenever I use Iframe or other tricks每当我使用 Iframe 或其他技巧时,预加载器都能正常工作

function myFunction() {
    myVar = setTimeout(function(){ document.body.addClass("loaded"); }, 3);
  }

  function myStopFunction() {
    clearTimeout(myVar);
  }

can anyone help me faking the preloading screen?谁能帮我伪造预加载屏幕?

setTimeout tells the browser to perform an action after the specified amount of time. setTimeout告诉浏览器在指定的时间后执行操作。 (The unit is miliseconds - 3ms might be a bit short). (单位是毫秒 - 3ms 可能有点短)。

clearTimeout tells the browser to cancel the action you set up with setTimeout . clearTimeout告诉浏览器取消您使用setTimeout设置的操作。

What you seem to be trying to do is adding the "loaded" class to body , so there is no need to use clearTimeout :您似乎想要做的是将"loaded"类添加到body ,因此无需使用clearTimeout

setTimeout(function(){ document.body.classList.add("loaded"); }, 3000);

will add the "loaded" class after three seconds.将在三秒后添加"loaded"类。

First, create a loader.首先,创建一个加载器。 It might just be an image with an infinite rotate on it by css, it might be complete overlay 1 z-index higher than that of your current content.它可能只是一个通过 css 无限旋转的图像,它可能是比当前内容高 1 z-index 的完整叠加层。 Whatever it is, doesn't really matter, just that it can obscure your 'loading' content.不管它是什么,都没有关系,只是它可以掩盖您的“加载”内容。 Give this div an id, ie loader.给这个 div 一个 id,即 loader。

Second, when everything loads, hide the loader, delete it if you want to.其次,当一切都加载时,隐藏加载器,如果你想删除它。

window.onload = function () {
   document.getElementById("loader").style.display = "none"; //HIDE THE ELEMENT
   document.getElementById("loader").style.remove(); // COMPLETELY REMOVE IT
}

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

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