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

html/css/js

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

HTML・CSS・JavaScriptを使って、モーダルウインドウのアニメーション5種類を実装する方法を紹介します。このサンプルでは、Drawer・Drop・Bounce・Blur・Skew の表示アニメーションを確認できます。通常のモーダルとは違う動きを付けたい場合や、サイトの雰囲気に合わせて表示演出を選びたい場合に利用できます。

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

デモ

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

<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>モーダルウインドウのアニメーション5選 vol.2</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>

  <!-- ① Drawer -->
  <section class="modal-animation-vol2_block">
    <h2>① Drawer(右から表示)</h2>
    <button class="modal-animation-vol2_button" type="button" data-modal-open="drawer">
      Drawer モーダルを開く
    </button>
  </section>

  <!-- ② Drop -->
  <section class="modal-animation-vol2_block">
    <h2>② Drop(上から表示)</h2>
    <button class="modal-animation-vol2_button" type="button" data-modal-open="drop">
      Drop モーダルを開く
    </button>
  </section>

  <!-- ③ Bounce -->
  <section class="modal-animation-vol2_block">
    <h2>③ Bounce(弾む表示)</h2>
    <button class="modal-animation-vol2_button" type="button" data-modal-open="bounce">
      Bounce モーダルを開く
    </button>
  </section>

  <!-- ④ Blur -->
  <section class="modal-animation-vol2_block">
    <h2>④ Blur(ぼかし解除)</h2>
    <button class="modal-animation-vol2_button" type="button" data-modal-open="blur">
      Blur モーダルを開く
    </button>
  </section>

  <!-- ⑤ Skew -->
  <section class="modal-animation-vol2_block">
    <h2>⑤ Skew(斜め表示)</h2>
    <button class="modal-animation-vol2_button" type="button" data-modal-open="skew">
      Skew モーダルを開く
    </button>
  </section>

  <!-- モーダル -->
  <div class="modal-animation-vol2_overlay" data-modal-overlay>

    <div class="modal-animation-vol2_modal" data-modal-box role="dialog" aria-modal="true">

      <div class="modal-animation-vol2_modal-title" data-modal-title>
        モーダルタイトル
      </div>

      <p class="modal-animation-vol2_modal-text" data-modal-text>
        モーダル本文です。
      </p>

      <button class="modal-animation-vol2_close" type="button" data-modal-close>
        閉じる
      </button>

    </div>

  </div>

  <script src="script.js"></script>

</body>
</html>

ファイル構成と設置方法

このサンプルは HTML・CSS・JavaScript の3ファイルだけで動作します。サーバー環境は不要で、ローカル環境でもそのまま動作確認できます。

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

HTMLファイル・CSSファイル・JavaScriptファイルを同じフォルダに配置してください。ブラウザで index.html を開くだけで、Drawer・Drop・Bounce・Blur・Skew の5種類のモーダルアニメーションを確認できます。


コメント