Multimodal

for Reveal.js

Multimodal

for Reveal.js

What can you use it for?

Multimodal can be used as a lightbox or actual modal to showcase images, video or HTML content. It can be triggered from text links, images, or buttons, or automatically when a slide is shown.

Example of HTML content

This is just content that is normally hidden.

Modal behaviour

Modal size

  • Content in modals will display at its original size, but is constrained to the maximum size of the modal.
  • The maximum size of modals is the size to the viewport, minus the margin as set in the Reveal config.
  • The minimum size of HTML modals is 300x200 pixels. This can be set in the config.

Triggers

A triggering element needs at least a data-modal-type.

a data-modal-url
an href attribute
a data-modal-url

Note: If the modal-content is not valid or can’t be found, no modal will be opened.

Navigation changes

  • The arrow keys will close the modal and go to the next slide
  • The space bar or escape key will only close the modal


Click the link above and then the arrow keys, space bar or escape key: the modal will be closed in all cases, but only arrow keys will navigate.

Slide modals

To automatically open a modal when a slide is shown, add the data-modal-type and data-modal-url attributes to the section element.

Slide modals

Events

There are 4 events that may help you do things in your modals: multimodal:show, multimodal:shown, multimodal:hide, and multimodal:hidden. Use it like this:

deck.addEventListener("multimodal:shown", async (event) => {
  const triggerInfo = event.detail.trigger;
  console.log("Trigger type:", triggerInfo.dataset.modalType);
});

Details are in event.detail. It references the trigger, the modal and more. A .multimodal-open class is also added to the .reveal element so that you can hook into this with CSS.

Override navigation

To prevent the user from accidentally navigating to another slide while the modal is open, you can add the data-modal-navblock attribute to the triggering element.

Show modal

Note that this blocks all keyboard navigation, but the escape key or any close buttons will still close the modal. It will NOT work in scroll mode.

Styling

The modal is styled with CSS variables, which are controlled through the Reveal.js options (see Global options). Some of these options can also be set per trigger:

Overlay

Add a data-modal-overlaycolor attribute to the trigger to change the overlay color on a per-trigger basis.

You may want to do this on slides that have a different background color.

Show modal

Background and padding

Graph

    Graph

The background color and padding can be set with the data-modal-background and data-modal-padding attributes. When using SVG's, this may come in handy. Both attributes can also be globally set in the options.

Image modals

Image modal from a text link

Show modal

As shown before, the href attribute can also be used.

Image modal from a clickable image

Both data-attribute and href attribute methods are shown.

Some glassesLeaves

	Some glasses


	Leaves

In this example, a small image is linked to a (different) large image in the modal.

Image modal from a clickable image, with the same image used

Mountain
Mountain

When a data-modal-url attribute is not added, and the link has an image as direct child of it, then that image will be used for the modal. This example limits the size of the image inside the outlined box.

Video modals

Video modal from a text link

Show video

Video modals will play when opened, close when finished, and finish when closed. Set this with videoautoplay and videoautohide settings in the options.

HTML modals

HTML modal from a local ID

Link to an ID

Long content like this will be scrollable in the modal.

HTML modal from an HTML file

The HTML content will use local styles.

Link to an HTML file

HTML modal from a Markdown file

The HTML content will use local styles

Link to a Markdown file

Markdown is converted to HTML when the modal is opened. It does not support Reveal.js’ element attributes.

Modal from an iframe

Both data-attribute and href attribute methods are shown.

Link to an external website
Link to a Youtube video

Global options


  1. border
  2. background
  3. closebuttonhtml
  4. cssautoload
  5. csspath
  6. htmlminwidth
  7. htmlminheight
  8. overlaycolor
  9. padding
  10. radius
  11. scalecorrection
  12. shadow
  13. slidemodalevent
  14. speed
  15. videoautoplay
  16. videocontrols
  17. videoautohide
  18. zoom
  19. zoomfrom

Option 1: background

This sets the standard background color of the modal. If the padding is set to 0 (default for images and video’s), you will not see it. HTML, iframe and media (images and video) are set separately.

Reveal.initialize({
    ...
    multimodal: {
        bgcolor: {
            html: "var(--r-background-color)",
            iframe: "var(--r-background-color)",
            media: "white"
        }
    },
    plugins: [ Multimodal ]
})

It can also be set per-trigger with data-modal-bgcolor.

Option 2: border

This sets the border around the dialog box.

Reveal.initialize({
    ...
    multimodal: {
        border: "1px solid white"
    },
    plugins: [ Multimodal ]
})

Option 3: closebuttonhtml

Allows you to add your own HTML for the close button.

Reveal.initialize({
    ...
    multimodal: {
        closebuttonhtml: '' // Can be any HTML, for example 
    },
    plugins: [ Multimodal ]
})

Option 4: cssautoload

Multimodal will load the CSS if this is set to true.

Reveal.initialize({
    ...
    multimodal: {
        cssautoload: true
    },
    plugins: [ Multimodal ]
})

If you import reveal.js-multimodal from npm, you will need to import the CSS file yourself. If you use 'import', then csspath should be set to false. If you know the path to the CSS file, you can use the csspath option and keep cssautoload set to true.

Option 5: csspath

If you want to change the styling, while using cssautoload, you can link to your own CSS file.

Reveal.initialize({
    ...
    multimodal: {
        csspath: "" // Can be a path to a CSS file
    },
    plugins: [ Multimodal ]
})

Option 6: htmlminwidth

This sets the minimum width of the HTML modals. The default is 100 pixels.

Reveal.initialize({
    ...
    multimodal: {
        htmlminwidth: "100px"
    },
    plugins: [ Multimodal ]
})

Option 7: htmlminheight

This sets the minimum height of the HTML modals. The default is 100 pixels.

Reveal.initialize({
    ...
    multimodal: {
        htmlminheight: "100px"
    },
    plugins: [ Multimodal ]
})

Option 8: overlaycolor

This sets the color of the overlay. Some people may call it a backdrop. The default is "rgba(0, 0, 0, 0.25)". That's like 25% black. You can use any CSS color here, but it’s best to use rgba for transparency.

Reveal.initialize({
    ...
    multimodal: {
        overlaycolor: "rgba(0, 0, 0, 0.25)"
    },
    plugins: [ Multimodal ]
})

Option 9: padding

This sets the standard padding of modals. HTML, iframe and media (images and video) are set separately.

Reveal.initialize({
    ...
    multimodal: {
        padding: {
            html: "1em",
            iframe: "0",
            media: "0"
        }
    },
    plugins: [ Multimodal ]
})

It can also be set per-trigger with data-modal-padding.

Option 10: radius

This sets the radius of the dialog box.

Reveal.initialize({
    ...
    multimodal: {
        radius: "0.5em"
    },
    plugins: [ Multimodal ]
})

Option 11: scalecorrection

This sets a scale correction, used in the border width and the close button. On small devices or screens, the border and close button may be too small. This option scales them back up.

Reveal.initialize({
    ...
    multimodal: {
        scalecorrection: true
    },
    plugins: [ Multimodal ]
})

Option 12: shadow

This sets the shadow around the dialog box. The default is a soft but dark shadow.

Reveal.initialize({
    ...
    multimodal: {
        outershadow: "0 0.5em 0.75em 0.5em rgba(0, 0, 0, 0.25)"
    },
    plugins: [ Multimodal ]
})

Option 13: slidemodalevent

This sets the event that triggers the modal on a slide, if that slide is set to show a modal.

Reveal.initialize({
    ...
    multimodal: {
        slidemodalevent: "slidetransitionend"
    },
    plugins: [ Multimodal ]
})

Option 14: speed

This sets the speed of the modal opening and closing.

Reveal.initialize({
    ...
    multimodal: {
        speed: 300
    },
    plugins: [ Multimodal ]
})

Option 15: videoautoplay

This sets the video to autoplay when opened.

Reveal.initialize({
    ...
    multimodal: {
        videoautoplay: true
    },
    plugins: [ Multimodal ]
})

Option 16: videocontrols

This sets the video to show controls when opened.

Reveal.initialize({
    ...
    multimodal: {
        videocontrols: true
    },
    plugins: [ Multimodal ]
})

Option 17: videoautohide

This sets the modal to close when the video in it ends.

Reveal.initialize({
    ...
    multimodal: {
        videoautohide: true
    },
    plugins: [ Multimodal ]
})

Option 18: zoom

This sets the modal to zoom in when opened.

Reveal.initialize({
    ...
    multimodal: {
        zoom: true
    },
    plugins: [ Multimodal ]
})

Option 19: zoomfrom

This sets the starting zoom factor of the modal when it is opened. It then zooms to factor 1.

Reveal.initialize({
    ...
    multimodal: {
        zoomfrom: 0.90
    },
    plugins: [ Multimodal ]
})