【CSS】脱jQueryで@keyframesを使用して丸いオブジェを円形に回転させ続けるアニメーションの実装方法のデモページ

※デベロッパーツール等でソースコードをご確認ください(Please check using Developer tools)

このページの内容が難しいと感じた方はこちら

Dummy Text

スポンサーリンク

Web制作会社LIGが運営するWebデザインスクール

CSS

.block {
  position: relative;
  width: 360px;
  margin: 150px auto 0;
  text-align: center;
}

.block .list {
  position: relative;
  width: 360px;
  height: 360px;
}

.block .list li {
  position: absolute;
  left: 0;
  top: 0;
  width: 180px;
  height: 180px;
  transform-origin: 100% 100%;
  opacity: 0;
}

.block .list li span {
  position: relative;
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #000;
  transition: transform .3s linear;
}

.block .list li span:before {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  opacity: .5;
  transition: transform .1s linear;
}

.block .list li.c-01 {
  transition: opacity .3s ease-out .2s;
  animation: rotation 70s linear infinite;
  transform: rotate(0);
}

.block .list li.c-01 span {
  background: #560f1b;
}

.block .list li.c-02 {
  transition: opacity .3s ease-out .4s;
  animation: rotation 70s linear -10s infinite;
  transform: rotate(51deg);
}

.block .list li.c-02 span {
  background: #055a3b;
}

.block .list li.c-03 {
  transition: opacity .3s ease-out .6s;
  animation: rotation 70s linear -20s infinite;
  transform: rotate(102deg);
}

.block .list li.c-03 span {
  background: #6b7cff;
}

.block .list li.c-04 {
  transition: opacity .3s ease-out .8s;
  animation: rotation 70s linear -30s infinite;
  transform: rotate(153deg);
}

.block .list li.c-04 span {
  background: #91b700;
}

.block .list li.c-05 {
  transition: opacity .3s ease-out 1s;
  animation: rotation 70s linear -40s infinite;
  transform: rotate(204deg);
}

.block .list li.c-05 span {
  background: #984000;
}

.block .list li.c-06 {
  transition: opacity .3s ease-out 1.2s;
  animation: rotation 70s linear -50s infinite;
  transform: rotate(255deg);
}

.block .list li.c-06 span {
  background: #56b2ff;
}

.block .list li.c-07 {
  transition: opacity .3s ease-out 1.4s;
  animation: rotation 70s linear -60s infinite;
  transform: rotate(306deg);
}

.block .list li.c-07 span {
  background: #000000;
}

.block .text {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.block.active .list li {
  opacity: 1;
  filter: alpha(opacity=100);
}

@keyframes rotation {
  0% {
   transform: rotate(0);
  }
  100% {
  transform: rotate(360deg);
  }
}

@media screen and (max-width:640px){
  .block {
    width: 300px;
  }

  .block .list {
    width: 300px;
    height: 300px;
  }

  .block .list li {
    width: 140px;
    height: 130px;
  }
}
  

JavaScript

window.onload = function() {
  document.getElementById("block").classList.add("active")
};