【发布时间】:2020-12-12 21:23:41
【问题描述】:
我正在尝试创建一个带有加载条和白色背景的预加载器,然后在 4 秒后以白色背景淡出。
预加载器应位于中心。现在它没有居中预加载器加上褪色效果不平滑。
这是我的 HTML:
const loaderWrapper = document.querySelector('.loaderWrapper');
const fadeEffect = setInterval(() => {
if (!loaderWrapper.style.opacity) {
loaderWrapper.style.opacity = 1;
}
if (loaderWrapper.style.opacity > 0) {
loaderWrapper.style.opacity -= 0.1;
} else {
clearInterval(fadeEffect);
}
}, 300);
html,
body {
height: 100%;
}
body {
background: rgb(199, 199, 199);
margin: 0;
display: flex;
align-items: center;
justify-content: center;
z-index: 1;
}
.loaderWrapper {
position: fixed;
top: 0;
width: 100%;
height: 100%;
background: #fff;
z-index: 1000;
}
.loader {
display: flex;
flex-direction: row;
align-items: center;
z-index: 999;
}
.loader .bar {
width: 10px;
height: 5px;
background: #000000;
margin: 2px;
animation: bar 1s infinite linear;
}
.loader .bar:nth-child(1) {
animation-delay: 0s;
}
.loader .bar:nth-child(2) {
animation-delay: 0.25s;
}
.loader .bar:nth-child(3) {
animation-delay: 0.5s;
}
@keyframes bar {
0% {
transform: scaleY(1) scaleX(0.5);
}
50% {
transform: scaleY(10) scaleX(1);
}
100% {
transform: scaleY(1) scaleX(0.5);
}
}
<div class="loaderWrapper">
<div class="loader">
<div class="bar"></div>
<div class="bar"></div>
<div class="bar"></div>
</div>
</div>
<div id="content">
<h1>This is our page title</h1>
<p>Lorem ipsum dolor sit amet.</p>
</div>
如何让加载栏图标居中,背景为白色,四秒后有平滑淡出效果?
这是 JSFiddle:https://jsfiddle.net/pqd0xfsk/1/
【问题讨论】:
-
查看我的答案,它不使用任何 javascript 并实现您真正想要的!
标签: javascript html css