Foundation モーダル


モーダル

モーダルは、現在のページの最上部に表示されるダイアログボックス/ポップアップウィンドウです。

クリックしてモーダルを開く

Heading in Modal.

Some text in the modal.

Some text in the modal.

×

モーダルを作成するには、ユニークな ID (<div id="myModal" など) を持つコンテナ要素に、 .reveal-modal クラスと data-reveal 属性を追加します。 モーダルを開くには、data-reveal-id="id" 属性を持つ要素を使用します。 id は、コンテナの id (例えば "myModal") に一致しなければなりません。

モーダルは、モーダルウィンドウの外側をクリックすると閉じます。また、閉じるために、(右上隅に要素を配置される) モーダル内部の <a> 要素に .close-reveal-modal クラスを追加することもできます。

注: foundation JS の初期を忘れないでください:

<!-- Trigger the Modal -->
<button type="button" class="button" data-reveal-id="myModal">Click To Open Modal</button>

<!-- The Modal Content -->
<div id="myModal" class="reveal-modal" data-reveal>
  <h2>Heading in Modal.</h2>
  <p>Some text in the modal.</p>
  <p>Some text in the modal.</p>
  <a class="close-reveal-modal">&times;</a>
</div>

<!-- Initialize Foundation JS -->
<script>
$(document).ready(function() {
    $(document).foundation();
})
</script>

結果:

Click To Open Modal

Heading in Modal.

Some text in the modal.

Some text in the modal.

×
Try it Yourself »

モーダルのサイズ

モーダルコンテナに、以下のクラスのいずれかを追加することで、モーダルのサイズを変更します:

注: タブレット、ラップトップやデスクトップのデフォルトは、幅が 80% で、小型デバイスでは、 常に 100% の全幅です。

<div id="myModal" class="reveal-modal tiny|small|medium|large|xlarge|full" data-reveal>

結果:

Tiny

Heading in Modal.

Some text in the modal.

×
Small

Heading in Modal.

Some text in the modal.

×
Medium

Heading in Modal.

Some text in the modal.

×
Large

Heading in Modal.

Some text in the modal.

×
XLarge

Heading in Modal.

Some text in the modal.

×
Full

Heading in Modal.

Some text in the modal.

×
Try it Yourself »

モーダルのネスト

最初のモーダル内に、新しく"トリガーボタン" を追加することにより、モーダル内にモーダルを配置することができます。 トリガーボタンと新しいモーダルの双方が、一致する新しい id を持っていることを確認してください:

<!-- Trigger the modal -->
<a href="#" class="button" data-reveal-id="myModal">Click To Open Modal</a>

<!-- The First Modal -->
<div id="myModal" class="reveal-modal" data-reveal>
  <h2>First Modal</h2>
  <p>Some text..</p>
  <p><a href="#" data-reveal-id="secondModal" class="button">Open Second Modal</a></p>
  <a class="close-reveal-modal">&times;</a>
</div>

<!-- The Second Modal -->
<div id="secondModal" class="reveal-modal" data-reveal>
  <h2>Tada! Second Modal</h2>
  <p>Some text..</p>
  <a class="close-reveal-modal">&times;</a>
</div>

結果:

First Modal

button below will open a new modal. If you open the new modal, foundation will close this modal (the first) and slide the new one into place over the first modal.

Open Second Modal

×

Tada! Second Modal

Easy peasy! Out with the old and in with the new!

Foundation slides the second modal into place after the first modal.

×
Try it Yourself »

2番目のモーダルは、最初のモーダルを置き換えます。2番目のを開いたときに、最初のモーダルを閉じたくない場合は、 2番目のモーダルに data-options="multiple_opened:true;" 属性を追加します:

<div id="secondModal" class="reveal-modal" data-reveal data-options="multiple_opened:true;">

結果:

First Modal

Open the second modal with the button below. This time, the first modal will NOT close (stays in the background of the second modal).

Open Second Modal

×

Tada! Second Modal

See the difference? The second modal lays on top of the first modal. If you close this modal, you'll see the first modal again.

×
Try it Yourself »