LoginSignup
28
14

More than 5 years have passed since last update.

ローディングスピナー

Last updated at Posted at 2019-02-21

spinner.gif

#!/bin/bash
spinner='⣾⣿⣽⣿⣻⣿⢿⣿⡿⣿⣿⢿⣿⡿⣿⣟⣿⣯⣿⣷⣿⣾⣷⣿'
l=${#spinner}
i=0
while :
do
  printf "\010\010"
  printf "${spinner:$i:2}"
  i=$(((i+2)%l))
  sleep 0.1
done

これをcssアニメーションを使ってscssで書くとこんな感じ

<div class="spinner"></div>
$str: (⣾⣿ ⣽⣿ ⣻⣿ ⢿⣿ ⡿⣿ ⣿⢿ ⣿⡿ ⣿⣟ ⣿⣯ ⣿⣷ ⣿⣾ ⣷⣿ ⣾⣿);
@keyframes spin {
  @for $i from 1 through length($str) {
    #{100*($i - 1)/(length($str)- 1)}% {
      content: "#{nth($str, $i)}";
    }
  }
}

.spinner {
  width: 100px;
  height: 100px;

  &::before {
    font-size: 100px;
    display: block;
    content: "#{nth($str, 1)}";
    animation: spin 2s linear infinite;
  }
}

See the Pen spinner by rnitta (@rnitta) on CodePen.

28
14
1

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
28
14