1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ローディング画面実装

Last updated at Posted at 2020-05-01

#行ったこと

  • ローデング画面の実装

#コード

HTML

<!-- ローディング用 -->
<div id="loading">
<!-- ローディング中に表示する画像-->
  <img src="example.gif" alt="loading">
</div>

<!-- コンテンツ-->
<div id="contents" class="hidden">
  <h1>example</h1>
</div>

CSS

#loading {
width: 100%;
height: 100%;
background-color: #fff;
position: relative;
}

#loading img {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}

.hidden {
display: none;
}

JavaScript

// ローディング画面のdivを取得
const loading = document.getElementById('loading');
const contents = document.getElementById('contents');

window.addEventListener('load', function () {
loading.style.display = 'none';
contents.classList.remove('hidden');
});

#プラグイン(pace.js)を使用する場合

<script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/pace.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/themes/black/pace-theme-center-circle.min.css" />
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?