Animate.cssの開始時間(Delay)アニメーション時間(Dulation)動作幅を調整する方法

ちょっとしたアニーメーションを付けるのに便利なAninmate.css ですが、実際に取り込んでみると、アニメーションの開始タイミングや、アニメーション時間、アニメーションの動作幅など、調整したいことも多々あるかと思います。

下記はbounceInというアニメーションを使っていますが、もう少しアニメーションの動作幅を控えめにしたいですよね。

テスト(デフォルト)

テスト(調整後)

「Webサイトからお問い合わせが来ない…」とお悩みの方必見!
当サイトのノウハウを詰め込んだ『Web集客の無料ガイド』をご提供

 

使い方

Animate.cssの使い方はいたってシンプルです。

  1. Animate.css サイトより、animate.cssファイルをダウンロードします。
     
  2. ダウンロードしたCSSファイルを読み込む
    1. <link rel="stylesheet" href="animate.min.css">
  3. アニメーションを付与した箇所にアニメーション名とanimatedクラスを追加する

    例:bounceInを追加したい場合
    <h1 class="bounceIn animated">テスト</h1>

 

調整方法

開始時間、アニメーション時間の調整

アニメーションの開始時刻や、アニメーションする時間の調整は下記のクラスを追加するだけです。

(例)

  1. <p class="bounceIn animated" id="animate">テスト</p>

CSS

  1. p#animate {
  2. animation-duration: 2s; /* アニメーションの時間 */
  3. animation-delay: 2s; /* アニメーション開始時間 */
  4. animation-iteration-count: infinite; /* アニメーションの繰り返し回数 */
  5. }

動作幅の調整

動作幅の調整は直接CSSファイルの修正を行うか、使うクラスをコピーしてCSSを上書きする必要があります。
それではbounceInを例に調整方法をご紹介します。

animate.cssを開くと下記の行があります。

@-webkit-keyframes bounceIn { }

@keyframes bounceIn { }

この二つがbounceInのアニメーションを行っています。
@-webkit- は、ベンダープレフィックスと呼ばれているもので、iOS8以下やAndroid4.4.4以下対応する場合は修正が必要です。必要ない場合はソースごと消しても大丈夫です。

bounceIn{ } の中は下記が書かれています。

  1. from,
  2. 20%,
  3. 40%,
  4. 60%,
  5. 80%,
  6. to {
  7. -webkit-animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
  8. animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
  9. }
  10.  
  11. 0% {
  12. opacity: 0;
  13. -webkit-transform: scale3d(0.3, 0.3, 0.3);
  14. transform: scale3d(0.3, 0.3, 0.3);
  15. }
  16.  
  17. 20% {
  18. -webkit-transform: scale3d(1.1, 1.1, 1.1);
  19. transform: scale3d(1.1, 1.1, 1.1);
  20. }
  21.  
  22. 40% {
  23. -webkit-transform: scale3d(0.9, 0.9, 0.9);
  24. transform: scale3d(0.9, 0.9, 0.9);
  25. }
  26.  
  27. 60% {
  28. opacity: 1;
  29. -webkit-transform: scale3d(1.03, 1.03, 1.03);
  30. transform: scale3d(1.03, 1.03, 1.03);
  31. }
  32.  
  33. 80% {
  34. -webkit-transform: scale3d(0.97, 0.97, 0.97);
  35. transform: scale3d(0.97, 0.97, 0.97);
  36. }
  37.  
  38. to {
  39. opacity: 1;
  40. -webkit-transform: scale3d(1, 1, 1);
  41. transform: scale3d(1, 1, 1);
  42. }

アニメーションの開始時 from(0%) 〜 アニメーションの終了時 to(100%)まで、transform: scale3d(1,1,1); で動作が書かれています。

scale3d() は、空間での拡大縮小を行うCSS関数です。

構文:scale3d(sx, sy, sz)
sx
 拡大縮小ベクトルの座標を表す
sy
 拡大縮小ベクトルの座標を表す
sz
 拡大縮小ベクトルの Z成分を表す

細かいことを気にせず、アニメーションの幅を縮めたい場合は、数値を1に近づける、アニメーションの幅を広げたいのあれば数値を1から遠ざければOKです。

実際に心地よい数値を入れ替えてみてください。

(例)

  1. @keyframes bounceIn {
  2. from,
  3. 20%,
  4. 40%,
  5. 60%,
  6. 80%,
  7. to {
  8. -webkit-animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
  9. animation-timing-function: cubic-bezier(0.215, 0.61, 0.355, 1);
  10.  
  11. }
  12.  
  13. 0% {
  14. opacity: 0;
  15. -webkit-transform: scale3d(0.98, 0.98, 0.98);
  16. transform: scale3d(0.98, 0.98, 0.98);
  17. }
  18.  
  19. 20% {
  20. -webkit-transform: scale3d(1.02, 1.02, 1.02);
  21. transform: scale3d(1.02, 1.02, 1.02);
  22. }
  23.  
  24. 40% {
  25. -webkit-transform: scale3d(0.99, 0.99, 0.99);
  26. transform: scale3d(0.99, 0.99, 0.99);
  27. }
  28.  
  29. 60% {
  30. opacity: 1;
  31. -webkit-transform: scale3d(1.01, 1.01, 1.01);
  32. transform: scale3d(1.01, 1.01, 1.01);
  33. }
  34.  
  35. 80% {
  36. -webkit-transform: scale3d(0.99, 0.99, 0.99);
  37. transform: scale3d(0.99, 0.99, 0.99);
  38. }
  39.  
  40. to {
  41. opacity: 1;
  42. -webkit-transform: scale3d(1, 1, 1);
  43. transform: scale3d(1, 1, 1);
  44. }
  45. }

テスト(デフォルト)

テスト(調整後)

関連タグ:

CPIの最新情報をTwitterでチェックできます!
@cpiadjp
次へ
前へ