CSS に関する迅速なヒントアニメーション ローダー

スコープ設定のカスタム プロパティと Animation-timing-function を使用して、アニメーション化された CSS ローダを作成しましょう。

CodePen にアクセスして、新しいペンを作成します。

ローダのマークアップを作成します。インライン カスタム プロパティを使用していることに注意してください。

<div class="loader" style="--count: 10">
  <span style="--index: 0"></span>
  <span style="--index: 1"></span>
  <span style="--index: 2"></span>
  <span style="--index: 3"></span>
  <span style="--index: 4"></span>
  <span style="--index: 5"></span>
  <span style="--index: 6"></span>
  <span style="--index: 7"></span>
  <span style="--index: 8"></span>
  <span style="--index: 9"></span>
</div>

ジェネレータ(Pug)を使用して行数を構成することもできます。

- const COUNT = 10
.loader(style=`--count: ${COUNT}`)
  - let i = 0
  while i < COUNT
    span(style=`--index: ${i}`)
    - i++

ローダーにスタイルを設定します。

loader {
  --size: 10vmin;

  height: var(--size);
  position: relative;
  width: var(--size);
}

絶対位置と、calctransform の組み合わせを使用して線を配置します。

.loader span {
  background: grey;
  height: 25%;
  left: 50%;
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%)
             rotate(calc(((360 / var(--count)) * var(--index)) * 1deg))
             translate(0, -125%);
  width: 10%;
}

--index に基づいて不透明度を適用します。

.loader span {
  opacity: calc(var(--index) / var(--count));
} 

物を回そう!

.loader {
  animation: spin 0.75s infinite steps(var(--count));
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

正しい効果を得るために steps(var(--count)) を使用していることに注意してください ✨

完了しました。🎉

これをご希望の場合、ツイートフォームでお知らせください。🐦

いつも最高の写真を