Skip to main content
Categories
HTML及びCSSポートフォリオ基礎的な学習学習

SVGアニメーション入門

  • Post Author
    By pitang1965
  • Post Date
    Sun Sep 13 2020
adorable-baby-blur-459976

ふとSVGを使ってみたいと思いました。

さらにそのSVGで簡単なアニメーションもやってみたいと思いました。

背景真っ白で面白みのないサイトが次のようになりました。デプロイ先はこちら(無料版のHerokuなので30 分間アクセスがないと起動まで待たされます)。

ピータンの天気予報

SVGファイルはIllustratorなどで編集できるようですが面倒だったのでgetwaves.ioを使ってみました。

以下の画面で適当に色を変えたりして、シャッフルしながら生成させた5つのSVGコードをコピーして、5つのsvgファイルとして保存しました。

getwaves.io

そしてcssファイルに以下を追記しました。

body { 
  background-color: #A2DAFF; 
  :
 :
  background-position: bottom;
  background-repeat: no-repeat;
  background-image: url(../img/cloud1.svg);

  animation-name: waveAnimation;
  animation-duration: 5s;
  animation-timing-function: linear;
  animation-delay: 0s;
  animation-iteration-count: infinite;
  animation-direction: normal;
  animation-fill-mode: none;
  animation-play-state: running;
}

@keyframes waveAnimation {
  20% {
    background-image: url(../img/cloud2.svg);
  }
  40% {
    background-image: url(../img/cloud3.svg);
  }
  60% {
    background-image: url(../img/cloud4.svg);
  }
  80% {
    background-image: url(../img/cloud5.svg);
  }
}

全体のソースコードはこちらにあります。