告诉我如何正确设置预加载器的条件:如果页面在10秒内没有完全加载,那么不显示预加载器?
setTimeout(function () {
fadePreLoader(preLoader);
}, 10000);
window.onload = function () {
fadePreLoader(preLoader);
};
如何结合这两个代码,使函数不会被执行fadePreLoader(preLoader);两次?
var preLoader = document.getElementById("before-load");
function fadePreLoader(el) {
el.style.opacity = 1;
var interPreLoader = setInterval(function () {
el.style.opacity = el.style.opacity - 0.05;
if (el.style.opacity <= 0.05) {
clearInterval(interPreLoader);
preLoader.style.display = "none";
}
}, 16);
}
setTimeout(function () {
fadePreLoader(preLoader);
}, 10000);
window.onload = function () {
fadePreLoader(preLoader);
};
#before-load {
position: fixed;
left: 0;
top: 0;
right: 0;
bottom: 0;
background: #ec1c24;
z-index: 1501;
border: 5px solid #ec1c24;
color:#fff;
}
.before-load__logo,
.before-load__preloader {
position: absolute;
margin: auto;
left: 0;
right: 0;
bottom: 0;
}
.before-load__logo {
width: 200px;
top: 75px;
}
.before-load__preloader {
width: 64px;
height: 64px;
top: 0;
}
<div id="before-load">
Внимание, работает прелоадер.
</div>
Тело сайта
这是可能的,通过关闭。你可以把
wasHidden它放在全局范围内,但它会变成一个更大的拐杖。为了不执行两次,去掉 setTimeout 和 onload
但是如何在没有单个脚本的情况下确定加载文档的开始,很可能是行不通的。
你可以“作弊”
无论脚本如何制作动画然后删除它,
然后脚本加载时间无关紧要