# reveal.js 中文文档(持续翻译中)

reveal.js 具有多种功能，包括嵌套幻灯片, Markdown内容, PDF 导出, 演讲者备注JavaScript API. 还有一个功能齐全的可视化编辑器和平台，可在以下位置共享reveal.js演示文稿 slides.com.

## 目录

#### 阅读更多

• 修改日志: 最新版本历史
• 示例: 使用reveal.js创建的演示，请添加您自己的演示！
• 浏览器支持: 浏览器支持和后备版本的说明。
• 插件: 可用于扩展reveal.js的插件列表。.

## 安装

### 基本设置

Reveal.js的核心非常易于安装。 您只需要下载此存储库的副本，然后直接在浏览器中打开index.html文件。

1.从https://github.com/hakimel/reveal.js/releases下载最新版本的reveal.js。
2.解压缩并将index.html中的示例内容替换为您自己的内容
3.在浏览器中打开index.html进行查看

### 完全设置

1. 安装 Node.js (4.0.0 or later)

2. 克隆reveal.js存储库

3. 导航到reveal.js文件夹

4. 安装依赖项

5. 提供演示并监视源文件的更改

6. 打开 http://localhost:8000 查看您的演示文稿

您可以使用以下命令来更改端口 npm start -- --port=8001.

### 文件夹结构

• css/ 核心样式，没有这些样式，项目就无法运行
• js/ 如上所述，但用于JavaScript
• plugin/ 为reveal.js开发的扩展的组件
• lib/ 所有其他第三方扩展 (JavaScript, CSS, fonts)

## 使用说明

### Markdown

#### 外部 Markdown

data-separator属性定义了水平幻灯片的正则表达式(默认为^\r?\n---\r?\n\$，这是一个以换行符为界的水平规则)。data-separator-vertical属性定义垂直幻灯片（默认情况下处于禁用状态）。data-separator-notes属性是一个正则表达式，用于指定当前幻灯片的演讲者注释的开头（默认为notes?:，因此它将同时匹配note:notes:）。 data-charset属性是可选的，它指定在加载外部文件时使用哪个字符集。

### 表示大小

If you wish to disable this behavior and do your own scaling (e.g. using media queries), try these settings:

### 依存关系

Reveal.js doesn’t rely on any third party scripts to work but a few optional libraries are included by default. These libraries are loaded as dependencies in the order they appear, for example:

You can add your own extensions using the same syntax. The following properties are available for each dependency object:

• src: Path to the script to load
• async: [optional] Flags if the script should load after reveal.js has started, defaults to false
• callback: [optional] Function to execute when the script has loaded
• condition: [optional] Function which must return true for the script to be loaded

### 准备事件

A ready event is fired when reveal.js has loaded all non-async dependencies and is ready to start navigating. To check if reveal.js is already ‘ready’ you can call Reveal.isReady().

Note that we also add a .ready class to the .reveal element so that you can hook into this with CSS.

### Auto-sliding

Presentations can be configured to progress through slides automatically, without any user input. To enable this you will need to tell the framework how many milliseconds it should wait between slides:

When this is turned on a control element will appear that enables users to pause and resume auto-sliding. Alternatively, sliding can be paused or resumed by pressing »A« on the keyboard. Sliding is paused automatically as soon as the user starts navigating. You can disable these controls by specifying autoSlideStoppable: false in your reveal.js config.

You can also override the slide duration for individual slides and fragments by using the data-autoslide attribute:

To override the method used for navigation when auto-sliding, you can specify the autoSlideMethod setting. To only navigate along the top layer and ignore vertical slides, set this to Reveal.navigateRight.

Whenever the auto-slide mode is resumed or paused the autoslideresumed and autoslidepaused events are fired.

### Keyboard Bindings

If you’re unhappy with any of the default keyboard bindings you can override them using the keyboard config option:

Slides can be nested within other slides to create vertical stacks (see Markup). When presenting, you use the left/right arrows to step through the main (horizontal) slides. When you arrive at a vertical stack you can optionally press the up/down arrows to view the vertical slides or skip past them by pressing the right arrow. Here’s an example showing a bird’s-eye view of what this looks like in action:

You can finetune the reveal.js navigation behavior by using the navigationMode config option. Note that these options are only useful for presnetations that use a mix of horizontal and vertical slides. The following navigation modes are available:

Value Description
default Left/right arrow keys step between horizontal slides. Up/down arrow keys step between vertical slides. Space key steps through all slides (both horizontal and vertical).
linear Removes the up/down arrows. Left/right arrows step through all slides (both horizontal and vertical).
grid When this is enabled, stepping left/right from a vertical stack to an adjacent vertical stack will land you at the same vertical index.

Consider a deck with six slides ordered in two vertical stacks:
1.1    2.1
1.2    2.2
1.3    2.3

If you’re on slide 1.3 and navigate right, you will normally move from 1.3 -> 2.1. With navigationMode set to “grid” the same navigation takes you from 1.3 -> 2.3.

You can swipe to navigate through a presentation on any touch-enabled device. Horizontal swipes change between horizontal slides, vertical swipes change between vertical slides. If you wish to disable this you can set the touch config option to false when initializing reveal.js.

If there’s some part of your content that needs to remain accessible to touch events you’ll need to highlight this by adding a data-prevent-swipe attribute to the element. One common example where this is useful is elements that need to be scrolled.

When working on presentation with a lot of media or iframe content it’s important to load lazily. Lazy loading means that reveal.js will only load content for the few slides nearest to the current slide. The number of slides that are preloaded is determined by the viewDistance configuration option.

To enable lazy loading all you need to do is change your src attributes to data-src as shown below. This is supported for image, video, audio and iframe elements.

Note that lazy loaded iframes ignore the viewDistance configuration and will only load when their containing slide becomes visible. Iframes are also unloaded as soon as the slide is hidden.

When we lazy load a video or audio element, reveal.js won’t start playing that content until the slide becomes visible. However there is no way to control this for an iframe since that could contain any kind of content. That means if we loaded an iframe before the slide is visible on screen it could begin playing media and sound in the background.

You can override this behavior with the data-preload attribute. The iframe below will be loaded
according to the viewDistance.

You can also change the default globally with the preloadIframes configuration option. If set to
true ALL iframes with a data-src attribute will be preloaded when within the viewDistance
regardless of individual data-preload attributes. If set to false, all iframes will only be

### API

The Reveal object exposes a JavaScript API for controlling navigation and reading state:

### Custom Key Bindings

Custom key bindings can be added and removed using the following Javascript API. Custom key bindings will override the default keyboard bindings, but will in turn be overridden by the user defined bindings in the keyboard config option.

For example

This allows plugins to add key bindings directly to Reveal so they can

• make use of Reveal’s pre-processing logic for key handling (for example, ignoring key presses when paused); and
• be included in the help overlay (optional)

### Slide Changed Event

A slidechanged event is fired each time the slide is changed (regardless of state). The event object holds the index values of the current slide as well as a reference to the previous and current slide HTML nodes.

Some libraries, like MathJax (see #226), get confused by the transforms and display states of slides. Often times, this can be fixed by calling their update or render function from this callback.

### Presentation State

The presentation’s current state can be fetched by using the getState method. A state object contains all of the information required to put the presentation back as it was when getState was first called. Sort of like a snapshot. It’s a simple object that can easily be stringified and persisted or sent over the wire.

### Slide States

If you set data-state="somestate" on a slide <section>, “somestate” will be applied as a class on the document element when that slide is opened. This allows you to apply broad style changes to the page based on the active slide.

Furthermore you can also listen to these changes in state via JavaScript:

### Slide Backgrounds

Slides are contained within a limited portion of the screen by default to allow them to fit any display and scale uniformly. You can apply full page backgrounds outside of the slide area by adding a data-background attribute to your <section> elements. Four different types of backgrounds are supported: color, image, video and iframe.

#### Color Backgrounds

All CSS color formats are supported, including hex values, keywords, rgba() or hsl().

#### Image Backgrounds

By default, background images are resized to cover the full page. Available options:

Attribute Default Description
data-background-image URL of the image to show. GIFs restart when the slide opens.
data-background-size cover See background-size on MDN.
data-background-position center See background-position on MDN.
data-background-repeat no-repeat See background-repeat on MDN.
data-background-opacity 1 Opacity of the background image on a 0-1 scale. 0 is transparent and 1 is fully opaque.

#### Video Backgrounds

Automatically plays a full size video behind the slide.

Attribute Default Description
data-background-video A single video source, or a comma separated list of video sources.
data-background-video-loop false Flags if the video should play repeatedly.
data-background-video-muted false Flags if the audio should be muted.
data-background-size cover Use cover for full screen and some cropping or contain for letterboxing.
data-background-opacity 1 Opacity of the background video on a 0-1 scale. 0 is transparent and 1 is fully opaque.

#### Iframe Backgrounds

Embeds a web page as a slide background that covers 100% of the reveal.js width and height. The iframe is in the background layer, behind your slides, and as such it’s not possible to interact with it by default. To make your background interactive, you can add the data-background-interactive attribute.

#### Background Transitions

Backgrounds transition using a fade animation by default. This can be changed to a linear sliding transition by passing backgroundTransition: 'slide' to the Reveal.initialize() call. Alternatively you can set data-background-transition on any section with a background to override that specific transition.

### Parallax Background

If you want to use a parallax scrolling background, set the first two properties below when initializing reveal.js (the other two are optional).

Make sure that the background size is much bigger than screen size to allow for some scrolling. View example.

### Slide Transitions

The global presentation transition is set using the transition config value. You can override the global transition for a specific slide by using the data-transition attribute:

You can also use different in and out transitions for the same slide:

You can choose from none, fade, slide, convex, concave and zoom.

It’s easy to link between slides. The first example below targets the index of another slide whereas the second targets a slide with an ID attribute (<section id="some-slide">):

You can also add relative navigation links, similar to the built in reveal.js controls, by appending one of the following classes on any element. Note that each element is automatically given an enabled class when it’s a valid navigation route based on the current slide.

### Fragments

Fragments are used to highlight individual elements on a slide. Every element with the class fragment will be stepped through before moving on to the next slide. Here’s an example: http://revealjs.com/#/fragments

The default fragment style is to start out invisible and fade in. This style can be changed by appending a different class to the fragment:

Multiple fragments can be applied to the same element sequentially by wrapping it, this will fade in the text on the first step and fade it back out on the second.

The display order of fragments can be controlled using the data-fragment-index attribute.

### Fragment events

When a slide fragment is either shown or hidden reveal.js will dispatch an event.

Some libraries, like MathJax (see #505), get confused by the initially hidden fragment elements. Often times this can be fixed by calling their update or render function from this callback.

### Code Syntax Highlighting

By default, Reveal is configured with highlight.js for code syntax highlighting. To enable syntax highlighting, you’ll have to load the highlight plugin (plugin/highlight/highlight.js) and a highlight.js CSS theme (Reveal comes packaged with the Monokai themes: lib/css/monokai.css).

Below is an example with clojure code that will be syntax highlighted. When the data-trim attribute is present, surrounding whitespace is automatically removed. HTML will be escaped by default. To avoid this, for example if you are using <mark> to call out a line of code, add the data-noescape attribute to the <code> element.

#### Line Numbers & Highlights

To enable line numbers, add data-line-numbers to your <code> tags. If you want to highlight specific lines you can provide a comma separated list of line numbers using the same attribute. For example, in the following example lines 4 and 8-11 are highlighted:

### Slide number

If you would like to display the page number of the current slide you can do so using the slideNumber and showSlideNumber configuration values.

### Overview mode

Press »ESC« or »O« keys to toggle the overview mode on and off. While you’re in this mode, you can still navigate between slides,
as if you were at 1,000 feet above your presentation. The overview mode comes with a few API hooks:

### Fullscreen mode

Just press »F« on your keyboard to show your presentation in fullscreen mode. Press the »ESC« key to exit fullscreen mode.

### Embedded media

Add data-autoplay to your media element if you want it to automatically start playing when the slide is shown:

If you want to enable or disable autoplay globally, for all embedded media, you can use the autoPlayMedia configuration option. If you set this to true ALL media will autoplay regardless of individual data-autoplay attributes. If you initialize with autoPlayMedia: false NO media will autoplay.

Note that embedded HTML5 <video>/<audio> and YouTube/Vimeo iframes are automatically paused when you navigate away from a slide. This can be disabled by decorating your element with a data-ignore attribute.

### Embedded iframes

reveal.js automatically pushes two post messages to embedded iframes. slide:start when the slide containing the iframe is made visible and slide:stop when it is hidden.

### Stretching elements

Sometimes it’s desirable to have an element, like an image or video, stretch to consume as much space as possible within a given slide. This can be done by adding the .stretch class to an element as seen below:

Limitations:

• Only direct descendants of a slide section can be stretched
• Only one descendant per slide section can be stretched

### Resize Event

When reveal.js changes the scale of the slides it fires a resize event. You can subscribe to the event to resize your elements accordingly.

### postMessage API

The framework has a built-in postMessage API that can be used when communicating with a presentation inside of another window. Here’s an example showing how you’d make a reveal.js instance in the given window proceed to slide 2:

When reveal.js runs inside of an iframe it can optionally bubble all of its events to the parent. Bubbled events are stringified JSON with three fields: namespace, eventName and state. Here’s how you subscribe to them from the parent window:

This cross-window messaging can be toggled on or off using configuration flags.

## PDF Export

Presentations can be exported to PDF via a special print stylesheet. This feature requires that you use Google Chrome or Chromium and to be serving the presentation from a web server.
Here’s an example of an exported presentation that’s been uploaded to SlideShare: http://www.slideshare.net/hakimel/revealjs-300.

### Separate pages for fragments

Fragments are printed on separate slides by default. Meaning if you have a slide with three fragment steps, it will generate three separate slides where the fragments appear incrementally.

If you prefer printing all fragments in their visible states on the same slide you can set the pdfSeparateFragments config option to false.

### Page size

Export dimensions are inferred from the configured presentation size. Slides that are too tall to fit within a single page will expand onto multiple pages. You can limit how many pages a slide may expand onto using the pdfMaxPagesPerSlide config option, for example Reveal.configure({ pdfMaxPagesPerSlide: 1 }) ensures that no slide ever grows to more than one printed page.

To enable the PDF print capability in your presentation, the special print stylesheet at /css/print/pdf.css must be loaded. The default index.html file handles this for you when print-pdf is included in the query string. If you’re using a different HTML template, you can add this to your HEAD:

### Instructions

1. Open your presentation with print-pdf included in the query string i.e. http://localhost:8000/?print-pdf. You can test this with revealjs.com?print-pdf.
2. Open the in-browser print dialog (CTRL/CMD+P).
3. Change the Destination setting to Save as PDF.
4. Change the Layout to Landscape.
5. Change the Margins to None.
6. Enable the Background graphics option.
7. Click Save.

Alternatively you can use the decktape project.

## Theming

The framework comes with a few different themes included:

• black: Black background, white text, blue links (default theme)
• white: White background, black text, blue links
• league: Gray background, white text, blue links (default theme for reveal.js < 3.0.0)
• beige: Beige background, dark text, brown links
• sky: Blue background, thin dark text, blue links
• night: Black background, thick white text, orange links
• serif: Cappuccino background, gray text, brown links
• simple: White background, black text, blue links
• solarized: Cream-colored background, dark green text, blue links

Each theme is available as a separate stylesheet. To change theme you will need to replace black below with your desired theme name in index.html:

## Speaker Notes

reveal.js comes with a speaker notes plugin which can be used to present per-slide notes in a separate browser window. The notes window also gives you a preview of the next upcoming slide so it may be helpful even if you haven’t written any notes. Press the »S« key on your keyboard to open the notes window.

A speaker timer starts as soon as the speaker view is opened. You can reset it to 00:00:00 at any time by simply clicking/tapping on it.

Notes are defined by appending an <aside> element to a slide as seen below. You can add the data-markdown attribute to the aside element if you prefer writing notes using Markdown.

Alternatively you can add your notes in a data-notes attribute on the slide. Like <section data-notes="Something important"></section>.

When used locally, this feature requires that reveal.js runs from a local web server.

If you’re using the external Markdown plugin, you can add notes with the help of a special delimiter:

#### Share and Print Speaker Notes

Notes are only visible to the speaker inside of the speaker view. If you wish to share your notes with others you can initialize reveal.js with the showNotes configuration value set to true. Notes will appear along the bottom of the presentations.

When showNotes is enabled notes are also included when you export to PDF. By default, notes are printed in a box on top of the slide. If you’d rather print them on a separate page, after the slide, set showNotes: "separate-page".

#### Speaker notes clock and timers

The speaker notes window will also show:

• Time elapsed since the beginning of the presentation. If you hover the mouse above this section, a timer reset button will appear.
• Current wall-clock time
• (Optionally) a pacing timer which indicates whether the current pace of the presentation is on track for the right timing (shown in green), and if not, whether the presenter should speed up (shown in red) or has the luxury of slowing down (blue).

The pacing timer can be enabled by configuring by the defaultTiming parameter in the Reveal configuration block, which specifies the number of seconds per slide. 120 can be a reasonable rule of thumb. Timings can also be given per slide <section> by setting the data-timing attribute. Both values are in numbers of seconds.

## Server Side Speaker Notes

In some cases it can be desirable to run notes on a separate device from the one you’re presenting on. The Node.js-based notes plugin lets you do this using the same note definitions as its client side counterpart. Include the required scripts by adding the following dependencies:

Then:

1. Install Node.js (4.0.0 or later)
2. Run npm install
3. Run node plugin/notes-server

## Plugins

Plugins should register themselves with reveal.js by calling Reveal.registerPlugin( 'myPluginID', MyPlugin ). Registered plugin instances can optionally expose an “init” function that reveal.js will call to initialize them.

When reveal.js is booted up via Reveal.initialize(), it will go through all registered plugins and invoke their “init” methods. If the “init” method returns a Promise, reveal.js will wait for that promise to be fullfilled before finshing the startup sequence and firing the ready event. Here’s an example of a plugin that does some asynchronous work before reveal.js can proceed:

If the init method does not return a Promise, the plugin is considered ready right away and will not hold up the reveal.js startup sequence.

### Retrieving Plugins

If you want to check if a specific plugin is registered you can use the Reveal.hasPlugin method and pass in a plugin ID, for example: Reveal.hasPlugin( 'myPlugin' ). If you want to retrieve a plugin instance you can use Reveal.getPlugin( 'myPlugin' ).

## Multiplexing

The multiplex plugin allows your audience to view the slides of the presentation you are controlling on their own phone, tablet or laptop. As the master presentation navigates the slides, all client presentations will update in real time. See a demo at https://reveal-js-multiplex-ccjbegmaii.now.sh/.

The multiplex plugin needs the following 3 things to operate:

1. Master presentation that has control
2. Client presentations that follow the master
3. Socket.io server to broadcast events from the master to the clients

#### Master presentation

Served from a static file server accessible (preferably) only to the presenter. This need only be on your (the presenter’s) computer. (It’s safer to run the master presentation from your own computer, so if the venue’s Internet goes down it doesn’t stop the show.) An example would be to execute the following commands in the directory of your master presentation:

1. npm install node-static
2. static

If you want to use the speaker notes plugin with your master presentation then make sure you have the speaker notes plugin configured correctly along with the configuration shown below, then execute node plugin/notes-server in the directory of your master presentation. The configuration below will cause it to connect to the socket.io server as a master, as well as launch your speaker-notes/static-file server.

You can then access your master presentation at http://localhost:1947

Example configuration:

#### Client presentation

Served from a publicly accessible static file server. Examples include: GitHub Pages, Amazon S3, Dreamhost, Akamai, etc. The more reliable, the better. Your audience can then access the client presentation via http://example.com/path/to/presentation/client/index.html, with the configuration below causing them to connect to the socket.io server as clients.

Example configuration:

#### Socket.io server

Server that receives the slideChanged events from the master presentation and broadcasts them out to the connected client presentations. This needs to be publicly accessible. You can run your own socket.io server with the commands:

1. npm install
2. node plugin/multiplex

Or you can use the socket.io server at https://reveal-js-multiplex-ccjbegmaii.now.sh/.

You’ll need to generate a unique secret and token pair for your master and client presentations. To do so, visit http://example.com/token, where http://example.com is the location of your socket.io server. Or if you’re going to use the socket.io server at https://reveal-js-multiplex-ccjbegmaii.now.sh/, visit https://reveal-js-multiplex-ccjbegmaii.now.sh/token.

You are very welcome to point your presentations at the Socket.io server running at https://reveal-js-multiplex-ccjbegmaii.now.sh/, but availability and stability are not guaranteed.

For anything mission critical I recommend you run your own server. The easiest way to do this is by installing now. With that installed, deploying your own Multiplex server is as easy running the following command from the reveal.js folder: now plugin/multiplex.

##### socket.io server as file static server

The socket.io server can play the role of static file server for your client presentation, as in the example at https://reveal-js-multiplex-ccjbegmaii.now.sh/. (Open https://reveal-js-multiplex-ccjbegmaii.now.sh/ in two browsers. Navigate through the slides on one, and the other will update to match.)

Example configuration:

It can also play the role of static file server for your master presentation and client presentations at the same time (as long as you don’t want to use speaker notes). (Open https://reveal-js-multiplex-ccjbegmaii.now.sh/ in two browsers. Navigate through the slides on one, and the other will update to match. Navigate through the slides on the second, and the first will update to match.) This is probably not desirable, because you don’t want your audience to mess with your slides while you’re presenting. ;)

Example configuration:

## MathJax

If you want to display math equations in your presentation you can easily do so by including this plugin. The plugin is a very thin wrapper around the MathJax library. To use it you’ll need to include it as a reveal.js dependency, find our more about dependencies here.

The plugin defaults to using LaTeX but that can be adjusted through the math configuration object. Note that MathJax is loaded from a remote server. If you want to use it offline you’ll need to download a copy of the library and adjust the mathjax configuration value.

Below is an example of how the plugin can be configured. If you don’t intend to change these values you do not need to include the math config object at all.

Read MathJax’s documentation if you need HTTPS delivery or serving of specific versions for stability.

#### MathJax in Markdown

If you want to include math inside of a presentation written in Markdown you need to wrap the formula in backticks. This prevents syntax conflicts between LaTeX and Markdown. For example: