CSS
 Computer >> コンピューター >  >> プログラミング >> CSS

CSSでrotateOutDownLeft(左下回転退場)アニメーション効果を作成する方法

CSSの rotateOutDownLeft(左下回転退場)アニメーションは、要素が左下を基準点として回転しながら画面から消えていくエフェクトです。transform-origin で回転の軸を要素の左下隅に設定し、90度の回転と同時に opacity を0へ変化させることで、滑らかにフェードアウトする動きを実現できます。

実装のポイント

  • transform-origin: left bottom — 回転の基準点を要素の左下に指定します。
  • @keyframes — アニメーションの開始時(0%)と終了時(100%)の状態を定義します。
  • animation-fill-mode: both — アニメーション開始前・終了後もスタイルを適用したまま維持します。
  • -webkit- プレフィックス — Safari などWebKit系ブラウザ向けの互換性対応として併記します。

サンプルコード

以下のコードを保存してブラウザで開くと、ロゴ画像が左下を軸に回転しながら消えていく様子を確認できます。「Reload page」ボタンをクリックするとページが再読み込みされ、アニメーションを何度でも再生できます。

<html>
   <head>
      <style>
         .animated {
            background-image: url(/css/images/logo.png);
            background-repeat: no-repeat;
            background-position: left top;
            padding-top:95px;
            margin-bottom:60px;
            -webkit-animation-duration: 10s;
            animation-duration: 10s;
            -webkit-animation-fill-mode: both;
            animation-fill-mode: both;
         }
         @-webkit-keyframes rotateOutDownLeft {
            0% {
               -webkit-transform-origin: left bottom;
               -webkit-transform: rotate(0);
               opacity: 1;
            }
            100% {
               -webkit-transform-origin: left bottom;
               -webkit-transform: rotate(90deg);
               opacity: 0;
            }
         }

         @keyframes rotateOutDownLeft {
            0% {
               transform-origin: left bottom;
               transform: rotate(0);
               opacity: 1;
            }
            100% {
               transform-origin: left bottom;
               transform: rotate(90deg);
               opacity: 0;
            }
         }
         .rotateOutDownLeft {
            -webkit-animation-name: rotateOutDownLeft;
            animation-name: rotateOutDownLeft;
         }
      </style>
   </head>

   <body>
      <div id = "animated-example" class = "animated rotateOutDownLeft"></div>
      <button onclick = "myFunction()">Reload page</button>
      <script>
         function myFunction() {
            location.reload();
         }
      </script>
   </body>
</html>

コードの解説

.animated クラスではアニメーションの全体設定を行っています。animation-duration: 10s でアニメーション全体の長さを10秒に設定し、animation-fill-mode: both によってアニメーション終了後も最終状態(不透明度0)が維持されます。

@keyframes rotateOutDownLeft の中では、0%の時点で transform: rotate(0)opacity: 1(初期状態)、100%の時点で transform: rotate(90deg)opacity: 0(回転して消えた状態)をそれぞれ定義しています。この補間によって、要素が左下を軸にゆっくりと倒れ込むように消えていく動きが生まれます。

  1. CSSで左上方向へ回転して消えるアニメーション(rotateOutUpLeft)を作る方法

    CSSのrotateOutUpLeftは、要素が左下を軸として反時計回りに回転しながら画面外へ消えていくアニメーション効果です。@keyframesで回転角度と不透明度(opacity)の変化を定義し、animation-nameを使って対象の要素に適用します。 実装例 以下のコードでは、ロゴ画像が10秒かけて左下を基点に-90度回転しながらフェードアウトしていきます。「Reload page」ボタンをクリックするとページが再読み込みされ、アニメーションを何度でも確認できます。 <html> <head> <style> .animated { bac

  2. CSSで実現する「右下を支点に回転しながら消える」アニメーション効果の作り方

    CSSのアニメーションを使えば、要素を右下(right bottom)を支点として回転させながらフェードアウトさせる演出が簡単に実装できます。この効果は一般的に rotateOutDownRight と呼ばれ、要素が画面から消える際の退場アニメーションとしてよく活用されます。rotateOutDownRightアニメーションの仕組みこのアニメーションでは、以下のCSSプロパティが重要な役割を果たします。transform-origin: right bottom; … 回転の基準点を要素の右下に設定します。transform: rotate(-90deg); … 要素を反時計回りに90度回転さ