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

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

使用HTML轻松创建漂亮的演示文稿的框架。查看演示.

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

目录

阅读更多

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

在线编辑

演示文稿是使用HTML或Markdown编写的,但是对于喜欢图形界面的人也有一个在线编辑器。 在 https://slides.com 尝试一下.

注意:国内使用在线编辑器可能需要科学上网

安装

基本设置仅用于编写演示文稿。 完全设置使您可以访问所有reveal.js功能和插件,例如演讲者注释以及对源进行更改所需的开发任务。

基本设置

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

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

完全设置

某些诸如外部Markdown和演讲者注释之类的reveal.js功能要求演示文稿必须在本地Web服务器上运行。以下说明将设置这样的服务器以及对Reveal.js源代码进行编辑所需的所有开发任务。

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

  2. 克隆reveal.js存储库

    1
    $ git clone https://github.com/hakimel/reveal.js.git
  3. 导航到reveal.js文件夹

    1
    $ cd reveal.js
  4. 安装依赖项

    1
    $ npm install
  5. 提供演示并监视源文件的更改

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

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

文件夹结构

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

使用说明

标记

下面是一个完整的revael.js工作示例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<html>
<head>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/white.css">
</head>
<body>
<div class="reveal">
<div class="slides">
<section>幻灯片 1</section>
<section>幻灯片 2</section>
</div>
</div>
<script src="js/reveal.js"></script>
<script>
Reveal.initialize();
</script>
</body>
</html>

表示标记的层次结构必须为.reveal> .slides> section,其中section代表一张幻灯片,并且可以无限制重复。如果您将多个section元素放在另一个section内,它们将显示为垂直幻灯片。垂直幻灯片的第一张是其他幻灯片的“封面”(在顶部),将包含在水平序列中。 例如:

1
2
3
4
5
6
7
8
9
<div class="reveal">
<div class="slides">
<section>单一的水平幻灯片</section>
<section>
<section>垂直幻灯片 1</section>
<section>垂直幻灯片 2</section>
</section>
</div>
</div>

Markdown

可以使用Markdown编写幻灯片。 要启用Markdown,请在您的<section>元素中添加data-markdown属性,并将内容包装在<textarea data-template>中,如下例所示。 您还需要(按顺序)将plugin/markdown/marked.jsplugin/markdown/markdown.js脚本添加到HTML文件中。

这是基于data-markdownPaul Irish修改使用marked支持GitHub Flavored Markdown。对缩进(避免制表符和空格混合)和换行(避免连续换行)敏感。

1
2
3
4
5
6
7
<section data-markdown>
<textarea data-template>
## Page title

A paragraph with some text and a [link](http://hakim.se).
</textarea>
</section>

外部 Markdown

你可以把你的内容写成一个单独的文件,并在运行时加载它。注意separator参数,它决定了在外部文件中如何分隔幻灯片:
data-separator属性定义了水平幻灯片的正则表达式(默认为^\r?\n---\r?\n$,这是一个以换行符为界的水平规则)。data-separator-vertical属性定义垂直幻灯片(默认情况下处于禁用状态)。data-separator-notes属性是一个正则表达式,用于指定当前幻灯片的演讲者注释的开头(默认为notes?:,因此它将同时匹配note:notes:)。 data-charset属性是可选的,它指定在加载外部文件时使用哪个字符集。

在本地使用时,这个功能需要reveal.js 从本地Web服务器运行。下面的例子指定了所有可用的选项:

1
2
3
4
5
6
7
8
9
10
<section data-markdown="example.md"
data-separator="^\n\n\n"
data-separator-vertical="^\n\n"
data-separator-notes="^Note:"
data-charset="iso-8859-15">
<!--
注意,Windows使用'\r\n'而不是'\n'作为换行符。
对于支持所有操作系统的正则表达式,请使用'\r?\n'而不是'\n'。
-->
</section>

元素属性

特殊语法(通过HTML注释)可用于向Markdown元素添加属性。这对于片段非常有用。

1
2
3
4
5
6
<section data-markdown>
<script type="text/template">
- Item 1 <!-- .element: class="fragment" data-fragment-index="2" -->
- Item 2 <!-- .element: class="fragment" data-fragment-index="1" -->
</script>
</section>

幻灯片属性

特殊语法(通过HTML注释)可用于将属性添加到Markdown生成的幻灯片<section>元素中。

1
2
3
4
5
6
<section data-markdown>
<script type="text/template">
<!-- .slide: data-background="#ff0000" -->
Markdown content
</script>
</section>

配置标记

我们使用marked来解析Markdown。 要自定义标记的渲染,您可以在配置显示时传入选项

1
2
3
4
5
6
7
Reveal.initialize({
// 传递给标记的选项
// 阅读 https://marked.js.org/#/USING_ADVANCED.md#options
markdown: {
smartypants: true
}
});

配置

在页面的最后,您需要通过运行以下代码来初始化显示。 请注意,所有的配置都是可选的,并且将默认指定为以下值。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
Reveal.initialize({

// 显示演示文稿控制箭头
controls: true,

// 通过提供提示来帮助用户学习控件,例如,当用户第一次遇到垂直幻灯片时通过弹跳向下箭头来帮助他们
controlsTutorial: true,

// 确定控件出现的位置,“边缘”(edges)或“右下”(bottom-right)
controlsLayout: 'bottom-right',

// 向后导航箭头的可见性规则:渐变、隐藏、可见
// "faded", "hidden", "visible"
controlsBackArrows: 'faded',

// 显示演示进度条
progress: true,

// 显示当前幻灯片的页码
slideNumber: false,

// 将当前幻灯片编号添加到URL散列中,以便重新加载页面/复制URL将返回到相同的幻灯片
hash: false,

// 将每个幻灯片更改推送到浏览器历史记录。这意味着 `hash: true`
history: false,

// 启用键盘快捷键进行导航
keyboard: true,

// 启用幻灯片概览模式
overview: true,

// 幻灯片的垂直居中
center: true,

// 在具有触摸输入的设备上启用触摸导航
touch: true,

// 循环演示
loop: false,

// 将显示方向更改为RTL
rtl: false,

// 阅读 https://github.com/hakimel/reveal.js/#navigation-mode
navigationMode: 'default',

// 每次演示加载时随机化幻灯片的顺序
shuffle: false,

// 全局打开和关闭片段
fragments: true,

// 标记是否在URL中包含当前片段,以便重新加载将您带到相同的片段位置
fragmentInURL: false,

// 标记演示文稿是否以嵌入式模式运行,即包含在屏幕的有限区域中
embedded: false,

// 当按下问号键时,如果我们应该显示帮助覆盖标志
help: true,

// 如果演讲者的笔记应该对所有观众可见,则标记
showNotes: false,

// 自动播放嵌入式媒体的全局覆盖 (video/audio/iframe)
// - null: 仅当存在数据自动播放时,媒体才会自动播放
// - true: 无论设置如何,所有媒体都会自动播放
// - false: 无论设置如何,都不会自动播放媒体
autoPlayMedia: null,

// 全局替换,用于预加载延迟加载的iframe
// - null: 在视图范围(viewDistance)内时,将加载具有data-src和data-preload的iframe,在可见时将加载仅具有data-src的iframe
// - true: 在viewDistance中时,将加载所有带有data-src的iframe
// - false: 所有带有data-src的iframe仅在可见时加载
preloadIframes: null,

// 自动前进到下一张幻灯片之间的毫秒数,设置为0时将禁用,可以通过使用幻灯片上的data-autoslide属性覆盖此值
autoSlide: 0,

// 用户输入后停止自动滑动
autoSlideStoppable: true,

// 自动滑动时使用此方法进行导航
autoSlideMethod: Reveal.navigateNext,

// 指定您认为每张幻灯片要花费的平均时间(以秒为单位)。 用于在扬声器视图中显示起搏计时器
defaultTiming: 120,

//通过鼠标滚轮启用幻灯片导航
mouseWheel: false,

// 如果不活动则隐藏光标
hideInactiveCursor: true,

// 隐藏光标之前的时间(以毫秒为单位)
hideCursorTime: 5000,

// 隐藏移动设备上的地址栏
hideAddressBar: true,

// 在iframe预览覆盖层中打开链接分别添加`data-preview-link`和`data-preview-link="false"`自定义每个链接
previewLinks: false,

// 过渡风格 无/淡入/滑动/凸出/凹入/缩放
transition: 'slide', // none/fade/slide/convex/concave/zoom

// 过渡速度 默认/快速/慢
transitionSpeed: 'default', // default/fast/slow

// 整页幻灯片背景的过渡样式 无/淡入/滑动/凸出/凹入/缩放
backgroundTransition: 'fade', // none/fade/slide/convex/concave/zoom

// 远离当前可见的幻灯片数量
viewDistance: 3,

// 视差背景图片
parallaxBackgroundImage: '', // e.g. "'https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg'"

// 视差背景尺寸
parallaxBackgroundSize: '', // CSS syntax, e.g. "2100px 900px"

// 每张幻灯片移动视差背景的像素数
// - 除非指定,否则自动计算
// - 设置为0以禁用沿轴移动
parallaxBackgroundHorizontal: null,
parallaxBackgroundVertical: null,

// 用于显示幻灯片的显示模式
display: 'block'

});

可以在初始化后使用configure方法:

1
2
3
4
5
// Turn autoSlide off
Reveal.configure({ autoSlide: 0 });

// Start auto-sliding every 5s
Reveal.configure({ autoSlide: 5000 });

表示大小

所有演示文稿均具有正常大小,即创作时的分辨率。 框架将根据该大小自动统一缩放演示文稿,以确保所有内容都适合任何给定的显示或视口。

请参阅以下有关尺寸调整的配置选项列表,包括默认值:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Reveal.initialize({

// ...

// The "normal" size of the presentation, aspect ratio will be preserved
// when the presentation is scaled to fit different resolutions. Can be
// specified using percentage units.
width: 960,
height: 700,

// Factor of the display size that should remain empty around the content
margin: 0.1,

// Bounds for smallest/largest possible scale to apply to content
minScale: 0.2,
maxScale: 1.5

});

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

1
2
3
4
5
6
7
8
9
10
Reveal.initialize({

// ...

width: "100%",
height: "100%",
margin: 0,
minScale: 1,
maxScale: 1
});

依存关系

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Reveal.initialize({
dependencies: [
// Interpret Markdown in <section> elements
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },

// Syntax highlight for <code> elements
{ src: 'plugin/highlight/highlight.js', async: true },

// Zoom in and out with Alt+click
{ src: 'plugin/zoom-js/zoom.js', async: true },

// Speaker notes
{ src: 'plugin/notes/notes.js', async: true },

// MathJax
{ src: 'plugin/math/math.js', async: true }
]
});

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().

1
2
3
Reveal.addEventListener( 'ready', function( event ) {
// event.currentSlide, event.indexh, event.indexv
} );

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:

1
2
3
4
// Slide every five seconds
Reveal.configure({
autoSlide: 5000
});

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:

1
2
3
4
5
<section data-autoslide="2000">
<p>After 2 seconds the first fragment will be shown.</p>
<p class="fragment" data-autoslide="10000">After 10 seconds the next fragment will be shown.</p>
<p class="fragment">Now, the fragment is displayed for 2 seconds before the next slide is shown.</p>
</section>

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:

1
2
3
4
5
6
7
Reveal.configure({
keyboard: {
13: 'next', // go to the next slide when the ENTER key is pressed
27: function() {}, // do something custom when ESC is pressed
32: null // don't do anything when SPACE is pressed (i.e. disable a reveal.js default binding)
}
});

Vertical Slide Navigation

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.

Touch Navigation

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.

Lazy Loading

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.

1
2
3
4
5
6
7
8
<section>
<img data-src="image.png">
<iframe data-src="http://hakim.se"></iframe>
<video>
<source data-src="video.webm" type="video/webm" />
<source data-src="video.mp4" type="video/mp4" />
</video>
</section>

Lazy Loading Iframes

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.

1
2
3
<section>
<iframe data-src="http://hakim.se" data-preload></iframe>
</section>

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
loaded when they become visible.

API

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Navigation
Reveal.slide( indexh, indexv, indexf );
Reveal.left();
Reveal.right();
Reveal.up();
Reveal.down();
Reveal.prev();
Reveal.next();
Reveal.prevFragment();
Reveal.nextFragment();

// Randomize the order of slides
Reveal.shuffle();

// Toggle presentation states, optionally pass true/false to force on/off
Reveal.toggleOverview();
Reveal.togglePause();
Reveal.toggleAutoSlide();

// Shows a help overlay with keyboard shortcuts, optionally pass true/false
// to force on/off
Reveal.toggleHelp();

// Change a config value at runtime
Reveal.configure({ controls: true });

// Returns the present configuration options
Reveal.getConfig();

// Fetch the current scale of the presentation
Reveal.getScale();

// Retrieves the previous and current slide elements
Reveal.getPreviousSlide();
Reveal.getCurrentSlide();

Reveal.getIndices(); // { h: 0, v: 0, f: 0 }
Reveal.getSlidePastCount();
Reveal.getProgress(); // (0 == first slide, 1 == last slide)
Reveal.getSlides(); // Array of all slides
Reveal.getTotalSlides(); // Total number of slides

// Returns the speaker notes for the current slide
Reveal.getSlideNotes();

// State checks
Reveal.isFirstSlide();
Reveal.isLastSlide();
Reveal.isOverview();
Reveal.isPaused();
Reveal.isAutoSliding();

// Returns the top-level DOM element
getRevealElement(); // <div class="reveal">...</div>

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.

1
2
Reveal.addKeyBinding( binding, callback );
Reveal.removeKeyBinding( keyCode );

For example

1
2
3
4
5
6
7
8
9
10
11
12
// The binding parameter provides the following properties
// keyCode: the keycode for binding to the callback
// key: the key label to show in the help overlay
// description: the description of the action to show in the help overlay
Reveal.addKeyBinding( { keyCode: 84, key: 'T', description: 'Start timer' }, function() {
// start timer
} )

// The binding parameter can also be a direct keycode without providing the help description
Reveal.addKeyBinding( 82, function() {
// reset timer
} )

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.

1
2
3
Reveal.addEventListener( 'slidechanged', function( event ) {
// event.previousSlide, event.currentSlide, event.indexh, event.indexv
} );

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.

1
2
3
4
5
6
7
8
9
10
Reveal.slide( 1 );
// we're on slide 1

var state = Reveal.getState();

Reveal.slide( 3 );
// we're on slide 3

Reveal.setState( state );
// we're back on slide 1

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:

1
2
3
Reveal.addEventListener( 'somestate', function() {
// TODO: Sprinkle magic
}, false );

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().

1
2
3
<section data-background-color="#ff0000">
<h2>Color</h2>
</section>

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.
1
2
3
4
5
6
<section data-background-image="http://example.com/image.png">
<h2>Image</h2>
</section>
<section data-background-image="http://example.com/image.png" data-background-size="100px" data-background-repeat="repeat">
<h2>This background image will be sized to 100px and repeated</h2>
</section>

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.
1
2
3
<section data-background-video="https://s3.amazonaws.com/static.slid.es/site/homepage/v1/homepage-video-editor.mp4,https://s3.amazonaws.com/static.slid.es/site/homepage/v1/homepage-video-editor.webm" data-background-video-loop data-background-video-muted>
<h2>Video</h2>
</section>

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.

1
2
3
<section data-background-iframe="https://slides.com" data-background-interactive>
<h2>Iframe</h2>
</section>

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).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Reveal.initialize({

// Parallax background image
parallaxBackgroundImage: '', // e.g. "https://s3.amazonaws.com/hakim-static/reveal-js/reveal-parallax-1.jpg"

// Parallax background size
parallaxBackgroundSize: '', // CSS syntax, e.g. "2100px 900px" - currently only pixels are supported (don't use % or auto)

// Number of pixels to move the parallax background per slide
// - Calculated automatically unless specified
// - Set to 0 to disable movement along an axis
parallaxBackgroundHorizontal: 200,
parallaxBackgroundVertical: 50

});

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:

1
2
3
4
5
6
7
<section data-transition="zoom">
<h2>This slide will override the presentation transition and zoom!</h2>
</section>

<section data-transition-speed="fast">
<h2>Choose from three transition speeds: default, fast or slow!</h2>
</section>

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<section data-transition="slide">
The train goes on …
</section>
<section data-transition="slide">
and on …
</section>
<section data-transition="slide-in fade-out">
and stops.
</section>
<section data-transition="fade-in slide-out">
(Passengers entering and leaving)
</section>
<section data-transition="slide">
And it starts again.
</section>

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">):

1
2
<a href="#/2/2">Link</a>
<a href="#/some-slide">Link</a>

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.

1
2
3
4
5
6
<a href="#" class="navigate-left">
<a href="#" class="navigate-right">
<a href="#" class="navigate-up">
<a href="#" class="navigate-down">
<a href="#" class="navigate-prev"> <!-- Previous vertical or horizontal slide -->
<a href="#" class="navigate-next"> <!-- Next vertical or horizontal 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:

1
2
3
4
5
6
7
8
9
10
11
12
<section>
<p class="fragment grow">grow</p>
<p class="fragment shrink">shrink</p>
<p class="fragment fade-out">fade-out</p>
<p class="fragment fade-up">fade-up (also down, left and right!)</p>
<p class="fragment fade-in-then-out">fades in, then out when we move to the next step</p>
<p class="fragment fade-in-then-semi-out">fades in, then obfuscate when we move to the next step</p>
<p class="fragment highlight-current-blue">blue only once</p>
<p class="fragment highlight-red">highlight-red</p>
<p class="fragment highlight-green">highlight-green</p>
<p class="fragment highlight-blue">highlight-blue</p>
</section>

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.

1
2
3
4
5
<section>
<span class="fragment fade-in">
<span class="fragment fade-out">I'll fade in, then out</span>
</span>
</section>

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

1
2
3
4
5
<section>
<p class="fragment" data-fragment-index="3">Appears last</p>
<p class="fragment" data-fragment-index="1">Appears first</p>
<p class="fragment" data-fragment-index="2">Appears second</p>
</section>

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.

1
2
3
4
5
6
Reveal.addEventListener( 'fragmentshown', function( event ) {
// event.fragment = the fragment DOM element
} );
Reveal.addEventListener( 'fragmenthidden', function( event ) {
// event.fragment = the fragment DOM element
} );

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).

1
2
3
4
5
6
Reveal.initialize({
// More info https://github.com/hakimel/reveal.js#dependencies
dependencies: [
{ src: 'plugin/highlight/highlight.js', async: true },
]
});

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.

1
2
3
4
5
6
7
8
9
<section>
<pre><code data-trim data-noescape>
(def lazy-fib
(concat
[0 1]
<mark>((fn rfib [a b]</mark>
(lazy-cons (+ a b) (rfib b (+ a b)))) 0 1)))
</code></pre>
</section>

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<pre><code class="hljs" data-line-numbers="4,8-11">
import React, { useState } from 'react';

function Example() {
const [count, setCount] = useState(0);

return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>
Click me
</button>
</div>
);
}
</code></pre>
line-numbers

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// Shows the slide number using default formatting
Reveal.configure({ slideNumber: true });

// Slide number formatting can be configured using these variables:
// "h.v": horizontal . vertical slide number (default)
// "h/v": horizontal / vertical slide number
// "c": flattened slide number
// "c/t": flattened slide number / total slides
Reveal.configure({ slideNumber: 'c/t' });

// You can provide a function to fully customize the number:
Reveal.configure({ slideNumber: function() {
// Ignore numbering of vertical slides
return [ Reveal.getIndices().h ];
}});

// Control which views the slide number displays on using the "showSlideNumber" value:
// "all": show on all views (default)
// "speaker": only show slide numbers on speaker notes view
// "print": only show slide numbers when printing to PDF
Reveal.configure({ showSlideNumber: 'speaker' });

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:

1
2
3
4
5
Reveal.addEventListener( 'overviewshown', function( event ) { /* ... */ } );
Reveal.addEventListener( 'overviewhidden', function( event ) { /* ... */ } );

// Toggle the overview mode programmatically
Reveal.toggleOverview();

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:

1
<video data-autoplay src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"></video>

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:

1
2
3
4
<section>
<h2>This video will use up the remaining space on the slide</h2>
<video class="stretch" src="http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"></video>
</section>

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.

1
2
3
Reveal.addEventListener( 'resize', function( event ) {
// event.scale, event.oldScale, event.size
} );

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:

1
<window>.postMessage( JSON.stringify({ method: 'slide', args: [ 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:

1
2
3
4
5
6
window.addEventListener( 'message', function( event ) {
var data = JSON.parse( event.data );
if( data.namespace === 'reveal' && data.eventName ==='slidechanged' ) {
// Slide changed, see data.state for slide number
}
} );

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

1
2
3
4
5
6
7
8
9
Reveal.initialize({
// ...

// Exposes the reveal.js API through window.postMessage
postMessage: true,

// Dispatches all reveal.js events to the parent window through postMessage
postMessageEvents: false
});

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:

1
2
3
4
5
6
7
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>

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.

Chrome Print Settings

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:

1
<link rel="stylesheet" href="css/theme/black.css" id="theme">

If you want to add a theme of your own see the instructions here: /css/theme/README.md.

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.

1
2
3
4
5
6
7
<section>
<h2>Some Slide</h2>

<aside class="notes">
Oh hey, these are some notes. They'll be hidden in your presentation, but you can see them if you open the speaker notes window (hit »S« on your keyboard).
</aside>
</section>

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

1
2
3
4
5
6
7
8
9
<section data-markdown="example.md" data-separator="^\n\n\n" data-separator-vertical="^\n\n" data-separator-notes="^Note:"></section>

# Title
## Sub-title

Here is some content...

Note:
This will only display in the notes window.

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:

1
2
3
4
5
6
7
8
Reveal.initialize({
// ...

dependencies: [
{ src: 'socket.io/socket.io.js', async: true },
{ src: 'plugin/notes-server/client.js', async: true }
]
});

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:

1
2
3
4
5
6
let MyPlugin = {
init: () => new Promise( resolve => setTimeout( resolve, 3000 ) )
};
Reveal.registerPlugin( 'myPlugin', MyPlugin );
Reveal.addEventListener( 'ready', () => console.log( 'Three seconds later...' ) );
Reveal.initialize();

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Reveal.initialize({
// other options...

multiplex: {
// Example values. To generate your own, see the socket.io server instructions.
secret: '13652805320794272084', // Obtained from the socket.io server. Gives this (the master) control of the presentation
id: '1ea875674b17ca76', // Obtained from socket.io server
url: 'https://reveal-js-multiplex-ccjbegmaii.now.sh' // Location of socket.io server
},

// Don't forget to add the dependencies
dependencies: [
{ src: '//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js', async: true },
{ src: 'plugin/multiplex/master.js', async: true },

// and if you want speaker notes
{ src: 'plugin/notes-server/client.js', async: true }

// other dependencies...
]
});

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Reveal.initialize({
// other options...

multiplex: {
// Example values. To generate your own, see the socket.io server instructions.
secret: null, // null so the clients do not have control of the master presentation
id: '1ea875674b17ca76', // id, obtained from socket.io server
url: 'https://reveal-js-multiplex-ccjbegmaii.now.sh' // Location of socket.io server
},

// Don't forget to add the dependencies
dependencies: [
{ src: '//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js', async: true },
{ src: 'plugin/multiplex/client.js', async: true }

// other dependencies...
]
});

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Reveal.initialize({
// other options...

multiplex: {
// Example values. To generate your own, see the socket.io server instructions.
secret: null, // null so the clients do not have control of the master presentation
id: '1ea875674b17ca76', // id, obtained from socket.io server
url: 'example.com:80' // Location of your socket.io server
},

// Don't forget to add the dependencies
dependencies: [
{ src: '//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js', async: true },
{ src: 'plugin/multiplex/client.js', async: true }

// other dependencies...
]

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Reveal.initialize({
// other options...

multiplex: {
// Example values. To generate your own, see the socket.io server instructions.
secret: '13652805320794272084', // Obtained from the socket.io server. Gives this (the master) control of the presentation
id: '1ea875674b17ca76', // Obtained from socket.io server
url: 'example.com:80' // Location of your socket.io server
},

// Don't forget to add the dependencies
dependencies: [
{ src: '//cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js', async: true },
{ src: 'plugin/multiplex/master.js', async: true },
{ src: 'plugin/multiplex/client.js', async: true }

// other dependencies...
]
});

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Reveal.initialize({
// other options ...

math: {
mathjax: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js',
config: 'TeX-AMS_HTML-full' // See http://docs.mathjax.org/en/latest/config-files.html
// pass other options into `MathJax.Hub.Config()`
TeX: { Macros: macros }
},

dependencies: [
{ src: 'plugin/math/math.js', async: true }
]
});

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:

1
`$$ J(\theta_0,\theta_1) = \sum_{i=0} $$`

License

MIT licensed

Copyright (C) 2019 Hakim El Hattab, http://hakim.se