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.
This is just content that is normally hidden.
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.
arrow keys
will close the modal and go to the next slidespace bar
or escape key
will only close the modalClick 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.
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
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.
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.
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:
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
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.
A triggering element can pass extra classes to the modal with data-modal-class
.
Show modal
Note: You can add multiple classes. Divide them by space or comma.
Show modal
As shown before, the href
attribute can also be used.
Both data-attribute and href attribute methods are shown.
In this example, a small image is linked to a (different) large image in the modal.
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.
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.
As shown before, the href attribute can also be used.
Link to an ID
Example of HTML content
This is just content that is normally hidden.
Long content like this will be scrollable in the modal.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam venenatis pretium cursus. Sed vel tincidunt dui. Aenean accumsan eget lectus eget aliquam. Vivamus risus neque, finibus at ex at, lobortis dignissim sem. Nunc euismod euismod justo, eget condimentum urna efficitur eleifend. Quisque ornare velit ac lectus mollis eleifend. Quisque faucibus id velit at eleifend. Sed sed nunc dui. Nullam eget tempor dolor.
Etiam tortor erat, fringilla ut sem vitae, interdum euismod dolor. Phasellus pellentesque at augue et pellentesque. Etiam non commodo ex, quis egestas risus. Cras ornare molestie lacus, ac gravida justo suscipit vel. Etiam consectetur est tortor, eu ornare augue tempus a. Mauris venenatis dapibus magna sit amet gravida. Pellentesque interdum nibh vel arcu tristique condimentum. Maecenas tincidunt sem eget dui posuere commodo.
Phasellus eu risus lacinia, imperdiet felis vel, condimentum est. Fusce tristique nisi lacus, non placerat turpis scelerisque id. Etiam massa urna, venenatis ac lacus sit amet, faucibus vestibulum metus. Nulla facilisi. Vestibulum porttitor varius dapibus. In sit amet justo condimentum, lacinia sapien non, lacinia odio. Nullam sollicitudin sapien eget turpis condimentum, nec aliquet sem venenatis. Sed efficitur risus quis neque fringilla, at fringilla purus varius.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam venenatis pretium cursus. Sed vel tincidunt dui. Aenean accumsan eget lectus eget aliquam. Vivamus risus neque, finibus at ex at, lobortis dignissim sem. Nunc euismod euismod justo, eget condimentum urna efficitur eleifend. Quisque ornare velit ac lectus mollis eleifend. Quisque faucibus id velit at eleifend. Sed sed nunc dui. Nullam eget tempor dolor.
The HTML content will use local styles.
Link to an HTML 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.
Both data-attribute and href attribute methods are shown.
Link to an external website
Link to a Youtube video
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: {
background: {
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
.
This sets the border color around the dialog box.
Reveal.initialize({
...
multimodal: {
bordercolor: "white"
},
plugins: [ Multimodal ]
})
This sets the border width around the dialog box.
Reveal.initialize({
...
multimodal: {
borderwidth: "1px"
},
plugins: [ Multimodal ]
})
Allows you to add your own HTML for the close button. Can be any HTML, but will need a data-modal-close
attribute.
Reveal.initialize({
...
multimodal: {
closebuttonhtml: '' // Can be changed to something like
},
plugins: [ Multimodal ]
})
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
.
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 ]
})
This sets the minimum width of the HTML modals. The default is 100 pixels.
Reveal.initialize({
...
multimodal: {
htmlminwidth: "100px"
},
plugins: [ Multimodal ]
})
This sets the minimum height of the HTML modals. The default is 100 pixels.
Reveal.initialize({
...
multimodal: {
htmlminheight: "100px"
},
plugins: [ Multimodal ]
})
This sets the color of the overlay. Some people may call it a backdrop. The default is "rgba(0, 0, 0, 0.30)"
. That's like 30% 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.30)"
},
plugins: [ Multimodal ]
})
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
.
This sets the radius of the dialog box.
Reveal.initialize({
...
multimodal: {
radius: "0.5em"
},
plugins: [ Multimodal ]
})
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 ]
})
This sets the shadow around the dialog box. The default is a soft but dark shadow.
Reveal.initialize({
...
multimodal: {
shadow: "0 0.5em 0.75em 0.5em rgba(0, 0, 0, 0.25)"
},
plugins: [ Multimodal ]
})
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 ]
})
This sets the speed of the modal opening and closing.
Reveal.initialize({
...
multimodal: {
speed: 300
},
plugins: [ Multimodal ]
})
This sets the video to autoplay when opened.
Reveal.initialize({
...
multimodal: {
videoautoplay: true
},
plugins: [ Multimodal ]
})
This sets the video to show controls when opened.
Reveal.initialize({
...
multimodal: {
videocontrols: true
},
plugins: [ Multimodal ]
})
This sets the modal to close when the video in it ends.
Reveal.initialize({
...
multimodal: {
videoautohide: true
},
plugins: [ Multimodal ]
})
This sets the modal to zoom in when opened.
Reveal.initialize({
...
multimodal: {
zoom: true
},
plugins: [ Multimodal ]
})
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 ]
})