【CSS】ローディングアニメーション実装サンプル集

ローディングアニメーション、待ち時間のあれですね。
使えそうなものを随時追加してこうと思います。

デザオ
ぐるぐるぐるぐるー
デザコト
ぐるぐるぐるぐるー

サンプル

コードを見る(HTML・CSS)

HTML

<div class="loader_01">
  <div class="double_a"></div>
  <div class="double_b"></div>
</div>

<div class="loader_02"></div>

<div class="loader_03"></div>

<div class="loader_04"></div>

<div class="loader_05">
  <div></div>
  <div></div>
  <div></div>
</div>

<div class="loader_06">
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
</div>

CSS

/* ---------- 01 ふたつの円がふくらむ ---------- */
.loader_01 {
  width: 30px;
  height: 30px;
  position: relative;
}
.loader_01 .double_a, .loader_01 .double_b {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background-color: #2b2a27;
  opacity: 0.6;
  position: absolute;
  top: 0;
  left: 0;
  animation: bounce 2.0s infinite ease-in-out;
}
.loader_01 .double_b {
  animation-delay: -1.0s;
}
@keyframes bounce {
  0%, 100% {
    transform: scale(0.0);
  } 50% {
    transform: scale(1.0);
  }
}

/* 動きを減らす設定のとき */
@media (prefers-reduced-motion: reduce) {
  .loader_01 .double_a, .loader_01 .double_b { animation: none; }
}

/* ---------- 02 ドーナツが回る ---------- */
.loader_02 {
  width: 1.5rem;
  height: 1.5rem;
  border: 4px solid #2b2a27;
  border-top-color: #e8dc6a;
  border-radius: 50%;
  animation: donut-spin 1s infinite linear;
}
@keyframes donut-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* 動きを減らす設定のとき */
@media (prefers-reduced-motion: reduce) {
  .loader_02 { animation: none; }
}

/* ---------- 03 二重線が回る ---------- */
.loader_03 {
  width: 1.5rem;
  height: 1.5rem;
  border: 4px double;
  border-color: #2b2a27 transparent;
  border-radius: 50%;
  animation: spin-spin 1s infinite linear;
}
@keyframes spin-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* 動きを減らす設定のとき */
@media (prefers-reduced-motion: reduce) {
  .loader_03 { animation: none; }
}

/* ---------- 04 点線が回る ---------- */
.loader_04 {
  position: relative;
  width: 1.5rem;
  height: 1.5rem;
  border: 4px dashed #2b2a27;
  border-radius: 50%;
}
.loader_04:before {
  content: '';
  position: absolute;
  width: 100%;
  height: 100%;
  top: -4px;
  left: -4px;
  border-width: 4px;
  border-style: dashed;
  border-color: #e8dc6a #e8dc6a transparent transparent;
  border-radius: 50%;
  animation: dashed-spin 1s infinite linear;
}
@keyframes dashed-spin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

/* 動きを減らす設定のとき */
@media (prefers-reduced-motion: reduce) {
  .loader_04:before { animation: none; }
}

/* ---------- 05 3つの点がはねる ---------- */
.loader_05 {
  display: flex;
}
.loader_05 > div {
  width: 1rem;
  height: 1rem;
  margin: 1rem .2rem;
  background: #2b2a27;
  border-radius: 50%;
  animation: bound .6s infinite alternate;
}
.loader_05 > div:nth-child(2) {
  animation-delay: .2s;
}
.loader_05 > div:nth-child(3) {
  animation-delay: .4s;
}
@keyframes bound {
  from {
    transform: translateY(0);
    opacity: 1;
  }
  to {
    transform: translateY(-1rem);
    opacity: .1;
  }
}

/* 動きを減らす設定のとき */
@media (prefers-reduced-motion: reduce) {
  .loader_05 > div { animation: none; }
}

/* ---------- 06 5本の棒がのびる ---------- */
.loader_06 {
  width: 60px;
  height: 40px;
  text-align: center;
  font-size: 10px;
}
.loader_06 > div {
  background-color: #2b2a27;
  height: 100%;
  width: 6px;
  display: inline-block;
  animation: stretchdelay 1.2s infinite ease-in-out;
}
.loader_06 > div:nth-of-type(2) {
  animation-delay: -1.1s;
}
.loader_06 > div:nth-of-type(3) {
  animation-delay: -1.0s;
}
.loader_06 > div:nth-of-type(4) {
  animation-delay: -0.9s;
}
.loader_06 > div:nth-of-type(5) {
  animation-delay: -0.8s;
}
@keyframes stretchdelay {
  0%, 40%, 100% {
    transform: scaleY(0.4);
  } 20% {
    transform: scaleY(1.0);
  }
}

/* 動きを減らす設定のとき */
@media (prefers-reduced-motion: reduce) {
  .loader_06 > div { animation: none; }
}

さいごに

デザオ
目が回りますねー
デザコト
待ち時間は短いのがいいですねー

ふたりの小言

デザコトauthor

あ、いいな、と思うWebデザインを紹介しています。デザインの参考に。やさしいデザインが多いです。Webデザインギャラリー『デザインのこと - Web design gallery』を運営しています。