biofriction-wp-theme/node_modules/foundation-sites/docs/pages/reveal.md

10 KiB
Raw Blame History

title description sass js video mui tags
Reveal Modal dialogs, or pop-up windows, are handy for prototyping and production. Foundation includes Reveal, our jQuery modal plugin, to make this easy for you. scss/components/_reveal.scss js/foundation.reveal.js vnT3bp07iHI true
modal

We hope youre loving these free documentation videos! If youd like to really accelerate your learning and master the world of front-end development, our Foundation online webinar training is the answer.

See the upcoming Foundation trainings →

Basics

A modal is just an empty container, so you can put any kind of content inside it, from text to forms to video to an entire grid.

Please note that we removed the option for AJAX loaded modals in Foundation 6. We did make it very easy to implement on your own though, check out a sample in the Advanced section.

To create a modal, add the class .reveal, the attribute data-reveal, and a unique ID to a container.

Watch this part in video

edit on codepen button
<div class="reveal" id="exampleModal1" data-reveal>
  <h1>Awesome. I Have It.</h1>
  <p class="lead">Your couch. It is mine.</p>
  <p>I'm a cool paragraph that lives inside of an even cooler modal. Wins!</p>
  <button class="close-button" data-close aria-label="Close modal" type="button">
    <span aria-hidden="true">&times;</span>
  </button>
</div>

You'll also need a way to open the modal. Add the attribute data-open to any element. The value of data-open should be the ID of the modal.

<p><button class="button" data-open="exampleModal1">Click me for a modal</button></p>

You'll also need a way to close the modal from inside. By default, modals will close if clicked outside of, or if the esc key is pressed. However, you'll generally also want to add your own click trigger. Add the attribute data-close to any element within the modal to add one.

You can use our handy close button styles to do this:

<button class="close-button" data-close aria-label="Close modal" type="button">
  <span aria-hidden="true">&times;</span>
</button>

Sizing

On small screens, a modal is always 100% of the width of the screen. On medium-sized screens and larger, the width changes to 600px (see the $reveal-width setting).

The size of a modal can be changed with these sizing classes, which are added to the modal container:

  • .tiny: 30% wide
  • .small: 50% wide
  • .large: 90% wide
  • .full: 100% width and height, defaults the escClose option to true, as well as creates a close button.

Watch this part in video

edit on codepen button
<div class="tiny reveal" id="exampleModal" data-reveal>
  <!-- ... -->
</div>

Click me for a tiny modal

OH I'M SO TIIINY

Click me for a small modal

I may be small, but I've got a big heart!

Click me for a large modal

I'm big, like bear!


Nested Modal

It's possible for modals to open other modals. Create a second modal with a unique ID, and then add a click trigger with data-open inside the first modal.

edit on codepen button
<p><button class="button" data-open="exampleModal2">Click me for a modal</button></p>

<!-- This is the first modal -->
<div class="reveal" id="exampleModal2" data-reveal>
  <h1>Awesome!</h1>
  <p class="lead">I have another modal inside of me!</p>
  <button class="button" data-open="exampleModal3">Click me for another modal!</button>
  <button class="close-button" data-close aria-label="Close reveal" type="button">
    <span aria-hidden="true">&times;</span>
  </button>
</div>

<!-- This is the nested modal -->
<div class="reveal" id="exampleModal3" data-reveal>
  <h2>ANOTHER MODAL!!!</h2>
  <button class="close-button" data-close aria-label="Close reveal" type="button">
    <span aria-hidden="true">&times;</span>
  </button>
</div>

Full-screen

A full-screen modal is 100% of the width and height of the window. Add the .full class to make it go.

Watch this part in video

edit on codepen button
<p><button class="button" data-toggle="exampleModal8">Click me for a full-screen modal</button></p>

<div class="full reveal" id="exampleModal8" data-reveal>
  <p>OH I'M SO FUUUUL</p>
  <img src="https://placekitten.com/1920/1280" alt="Introspective Cage">
  <button class="close-button" data-close aria-label="Close reveal" type="button">
    <span aria-hidden="true">&times;</span>
  </button>
</div>

Advanced Options

No Overlay

To remove the overlay, add the attribute data-overlay="false" to the modal.

edit on codepen button
<p><button class="button" data-toggle="exampleModal9">Click me for an overlay-lacking modal</button></p>

<div class="reveal" id="exampleModal9" data-reveal data-overlay="false">
  <p>I feel so free!</p>
  <button class="close-button" data-close aria-label="Close reveal" type="button">
    <span aria-hidden="true">&times;</span>
  </button>
</div>

Animations

To use animations from the Motion UI library, include the data-animation-in="someAnimationIn" and data-animation-out="someAnimationOut" attributes. If you want to adjust the speed or timing, include it the attributes like data-animation-in="someAnimationIn fast".

Watch this part in video

edit on codepen button
<p><button class="button" data-toggle="animatedModal10">Click me for a modal</button></p>

<div class="reveal" id="animatedModal10" data-reveal data-close-on-click="true" data-animation-in="spin-in" data-animation-out="spin-out">
  <h1>Whoa, I'm dizzy!</h1>
  <p class="lead">There are many options for animating modals, check out the Motion UI library to see them all</p>
  <button class="close-button" data-close aria-label="Close reveal" type="button">
    <span aria-hidden="true">&times;</span>
  </button>
</div>

AJAX

To use AJAX to load your modal content, use the code snippet below.

var $modal = $('#modal');

$.ajax('/url')
  .done(function(resp){
    $modal.html(resp).foundation('open');
});

Accessibility

Modals by default are accessible through the use of various ARIA attributes. To make a modal even more accessible, designate a label to the modal by adding aria-labelledby="exampleModalHeader11" to the container and id="exampleModalHeader11" to the element you want to designate as the label.

edit on codepen button
<p><button class="button" data-open="exampleModal11">Click me for a modal</button></p>

<div class="reveal" id="exampleModal11" aria-labelledby="exampleModalHeader11" data-reveal>
  <h1 id="exampleModalHeader11">Label for the Modal!</h1>
  <p class="lead">I am even more accessible than the other modals.</p>
  <button class="close-button" data-close aria-label="Close Accessible Modal" type="button">
    <span aria-hidden="true">&times;</span>
  </button>
</div>