<!-- ローダーの要素 -->
<div id="js-loader" class="container">
<div class="loader"></div>
</div>
<!-- ローディング後の表示要素 -->
<div class="wrapper">
<p class="text">Loading is complete</p>
</div>
body {
background-color: #333;
color: #fff;
font-family: "Teko", sans-serif;
}
.wrapper {
height: 100vh;
text-align: center;
}
.text {
line-height: 100vh;
}
/* ここからローダーのスタイルを記述 */
.container {
/* 子要素を中央揃え */
display: grid;
place-content: center;
/* 要素を一番手前に表示 */
position: absolute;
z-index: 1;
/* 親要素を画面幅いっぱいにする */
width: 100vw;
height: 100vh;
background-color: #333;
transition: opacity 1s ease;
}
.loader {
width: 50px;
height: 50px;
border: 6px solid #f3f3f3;
border-top: 6px solid #3d5aff;
border-radius: 50%;
animation: spin 2s linear infinite;
}
@keyframes spin {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
View Compiled
// ローダーのコンテナ要素を取得
const loader = document.getElementById("js-loader");
// 3秒後にopacityを0にする
setTimeout(() => {
loader.style.opacity = 0;
}, 3000);
// アニメーションが終わると、要素を取り除く
loader.addEventListener("transitionend", () => {
loader.remove();
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.