モーダルウインドウのアニメーション5選 vol.1【HTML/CSS/JavaScript・サンプルコード付き】

html/css/js

モーダルウインドウのアニメーション5選vol.1

HTML・CSS・JavaScriptを使って、モーダルウインドウのアニメーション5種類を実装する方法を紹介します。このサンプルでは、フェードイン・スライドアップ・ズームイン・フリップ・ローテートの表示方法をそれぞれ確認できます。サイトのデザインや演出に合わせて、好みのアニメーションを選びたい場合に便利です。

コードについて 本記事のコードはサンプルコードです。ご利用前に必ず動作確認を行ってください。
免責事項 本コードの利用により発生した損害について、当サイトは一切の責任を負いません。

デモ

コードをコピーして使おう!

<!DOCTYPE html>
<html lang="ja">
<head>

  <!-- 文字コードを指定します -->
  <meta charset="UTF-8">

  <!-- ページタイトルです -->
  <title>モーダルウインドウのアニメーション5選vol.1</title>

  <!-- CSSファイルを読み込みます -->
  <link rel="stylesheet" href="style.css">

</head>
<body>

  <!-- ① Fade モーダル -->
  <section class="modal-animation-vol1_block">

    <h2>① Fade(ふわっと表示)</h2>

    <button class="modal-animation-vol1_button" type="button" data-modal-open="fade">
      Fade モーダルを開く
    </button>

  </section>

  <!-- ② Slide モーダル -->
  <section class="modal-animation-vol1_block">

    <h2>② Slide(下から表示)</h2>

    <button class="modal-animation-vol1_button" type="button" data-modal-open="slide">
      Slide モーダルを開く
    </button>

  </section>

  <!-- ③ Zoom モーダル -->
  <section class="modal-animation-vol1_block">

    <h2>③ Zoom(拡大表示)</h2>

    <button class="modal-animation-vol1_button" type="button" data-modal-open="zoom">
      Zoom モーダルを開く
    </button>

  </section>

  <!-- ④ Flip モーダル -->
  <section class="modal-animation-vol1_block">

    <h2>④ Flip(回転表示)</h2>

    <button class="modal-animation-vol1_button" type="button" data-modal-open="flip">
      Flip モーダルを開く
    </button>

  </section>

  <!-- ⑤ Rotate モーダル -->
  <section class="modal-animation-vol1_block">

    <h2>⑤ Rotate(軽く回転表示)</h2>

    <button class="modal-animation-vol1_button" type="button" data-modal-open="rotate">
      Rotate モーダルを開く
    </button>

  </section>

  <!-- モーダル背景です -->
  <div class="modal-animation-vol1_overlay" data-modal-overlay>

    <!-- モーダル本体です -->
    <div class="modal-animation-vol1_modal" data-modal-box role="dialog" aria-modal="true">

      <!-- モーダルタイトルです -->
      <div class="modal-animation-vol1_modal-title" data-modal-title>
        モーダルタイトル
      </div>

      <!-- モーダル本文です -->
      <p class="modal-animation-vol1_modal-text" data-modal-text>
        モーダル本文が入ります。
      </p>

      <!-- モーダルを閉じるボタンです -->
      <button class="modal-animation-vol1_close" type="button" data-modal-close>
        閉じる
      </button>

    </div>

  </div>

  <!-- JavaScriptファイルを読み込みます -->
  <script src="script.js"></script>

</body>
</html>

ファイル構成と設置方法

このサンプルでは、HTML・CSS・JavaScriptをそれぞれ別ファイルに分けて使用します。index.htmlstyle.cssscript.js を同じフォルダに配置してください。

sample/
├── index.html
├── style.css
└── script.js
  

index.html をブラウザで開くと、5種類のモーダルアニメーションを確認できます。各ボタンをクリックすると、Fade・Slide・Zoom・Flip・Rotate のいずれかの動きでモーダルウインドウが表示されます。


コメント