Skip to content

Commit 6e61715

Browse files
author
Martino
committed
Add autoappear mode
1 parent 7809eb9 commit 6e61715

File tree

8 files changed

+578
-252
lines changed

8 files changed

+578
-252
lines changed

CHANGELOG.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Changelog
2+
3+
4+
## [1.1.1] - 2021-11-27
5+
### Added
6+
- Added a new `autoappear` mode, for use in cases where adding animation classes is too much of a hassle, like inside Markdown.
7+
- Started keeping the changelog.
8+
9+
10+
11+
## [1.1.0] - 2021-09-03
12+
### Added
13+
- Added Github corner badge
14+
15+
### Changed
16+
- Changed readme
17+
18+
19+
20+
## [1.0.9] - 2021-06-30
21+
### Changed
22+
- Fixed a bug where '=' was '=='.
23+
24+
25+
26+
## [1.0.8] - 2021-06-27
27+
### Added
28+
- Choose an event at which Appearance launches its animations
29+
30+
### Changed
31+
- Appearance now shows the complete slides from the overview
32+
33+
34+
35+
## [1.0.7] - 2020-06-28
36+
### Changed
37+
- Clearing timeouts that are in past slides. This solves 'hanging' Appearance items if you slide back and forth.
38+
39+
40+
41+
## [1.0.6] - 2020-06-28
42+
### Changed
43+
- Fix bug that hid Appearance items in PDF exports.
44+
45+
46+
47+
## [1.0.5] - 2020-05-20
48+
### Added
49+
- Added compatibility with the new Reveal.js 4 that changes the way plugins work.
50+
51+
52+
53+
## [1.0.4] - 2020-05-20
54+
### Added
55+
- The 1.0.4 release is compatible with Reveal.js 3. Reveal versions lower than 4 have no "slidetransitionend" event, so this release also has the Transit.js plugin included (see https://github.com/Martinomagnifico/reveal.js-transit for more information).

README.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,11 @@ In Powerpoint you can make slides with items that appear automatically with effe
1212

1313
We do not want the animations to start during the slide transition, so we wait for the slide transition to end. Then the animations will start automatically if the HTML is set up to use Appearance.
1414

15+
Version 1.1.1 adds an `autoappear` mode for use in cases where adding animation classes is too much of a hassle, like inside Markdown.
1516

1617

17-
## Installation
18-
19-
The Appearance plugin has been rewritten for Reveal.js version 4.
2018

21-
If you want to use Appearance with an older version of Reveal, use the [1.0.4 version](https://github.com/Martinomagnifico/reveal.js-appearance/releases).
19+
## Installation
2220

2321
### Regular installation
2422

@@ -94,6 +92,23 @@ It is easy to set up your HTML structure for Appearance:
9492
<li class="animated bounceInLeft">It adds some attention.</li>
9593
</ul>
9694
```
95+
When you are working with Markdown, this can be a chore so if you do not want to add all these classes, you can set the option `autoappear` to `true` (see Configuration below) and let Appearance do the heavy work. You do not need to add any markup and it will stay like this:
96+
97+
```html
98+
<ul>
99+
<li>Add it to any text element</li>
100+
<li>Like list items, or headers.</li>
101+
<li>It adds some attention.</li>
102+
</ul>
103+
```
104+
or this:
105+
106+
```markdown
107+
* Add it to any text element
108+
* Like list items, or headers.
109+
* It adds some attention.
110+
111+
```
97112

98113

99114
## Configuration
@@ -108,7 +123,9 @@ Reveal.initialize({
108123
visibleclass: 'in',
109124
hideagain: true,
110125
delay: 300,
111-
appearevent: 'slidetransitionend'
126+
appearevent: 'slidetransitionend',
127+
autoappear: false,
128+
autoelements: false
112129
},
113130
plugins: [ Appearance ]
114131
});
@@ -119,6 +136,9 @@ Reveal.initialize({
119136
* **`hideagain`**: Change this (true/false) if you want to see the shown elements if you go back.
120137
* **`delay`**: Base time in ms between appearances.
121138
* **`appearevent`**: Use a specific event at which Appearance starts.
139+
* **`autoappear`**: Use this when you do not want to add classes to each item that you want to appear, and just let Appearance add animation classes to (all of) the provided elements in the presentation. See "Using 'autoappear'" mode below.
140+
* **`autoelements`**: These are the elements that `autoappear` will target. Each element has a selector and an animation class. If `autoappear` is off, the elements will still get animation if the section contains a `data-autoappear` attribute.
141+
122142

123143
### Changing the 'appearevent'
124144
When you navigate from slide to slide, you can set transition effects in Reveal. These effects take some time. That's why, by default, Appearance only starts when the slide transition has ended.
@@ -134,6 +154,22 @@ These same event triggers can be set through the data-attribute `data-appeareven
134154
When using Appearance inside an autoanimate slide, and changing the appearevent to `slidechanged` or `auto`, keep in mind that Reveal transforms opacity for all non-autoanimate items, while Appearance does the same on most of the effects. To avoid strange behaviour, wrap these Appearance items in a parent. For example, a list of animated bullet points works well, because the animated class is on the children, not the parent. Separate headings or other elements do not have that, so should be wrapped.
135155

136156

157+
### Using 'autoappear' mode
158+
Sometimes (for example with Markdown), adding classes to elements is a chore. Appearance can automatically add animation classes to specific elements in the presentation.
159+
160+
With the option `autoappear` set to `true`, ALL elements in the presentation that have a certain selector will get an animation. These selectors and the animations can be set in the configuration options like this:
161+
162+
```javascript
163+
autoelements: {
164+
'ul li': 'fadeInLeft',
165+
'ol li': 'fadeInRight'
166+
}
167+
```
168+
You can add any selector and animation class to this object.
169+
170+
With the option `autoappear` set to `false`, the above still works, but only on a data-attribute basis. ONLY elements in the presentation that are inside sections or fragments with a data-attribute of `data-autoappear` will be animated automatically.
171+
172+
137173

138174
## Now change it
139175

demo.html

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
<meta name="author" content="Martinomagnifico">
99
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
1010
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
11-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/reveal.js/dist/reset.css">
12-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/reveal.js/dist/reveal.css">
13-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/reveal.js/dist/theme/black.css">
11+
<link rel="stylesheet" href="../dist/reset.css">
12+
<link rel="stylesheet" href="../dist/reveal.css">
13+
<link rel="stylesheet" href="../dist/theme/black.css">
1414
<link rel="stylesheet" href="css/demo.css">
1515
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css">
1616
<link rel="stylesheet" href="plugin/appearance/appearance.css">
@@ -26,7 +26,7 @@
2626
<h1 class="animated flipInX slow">Appearance</h1>
2727
<h3 class="animated flipInX slow" data-delay="700">for Reveal.js</h3>
2828
</section>
29-
<section class="center"><small>In Powerpoint you can make slides with items that appear automatically with effects. Appearance is a plugin for Reveal.js that does the same. </small><br><br><small>Appearance is easy to set up. It uses Animate.css by Daniel Eden for the animations, with some changes in a separate CSS file to allow for a non-animated state. </small>
29+
<section class="center"><small>In Powerpoint you can make slides with items that appear automatically with effects. Appearance is a plugin for Reveal.js that does the same. </small><small>Appearance is easy to set up. It uses Animate.css by Daniel Eden for the animations, with some changes in a separate CSS file to allow for a non-animated state. </small>
3030
<p>Let's check out what Appearance does:</p>
3131
</section>
3232
<section class="center">
@@ -82,15 +82,23 @@ <h3>Change when Appearance starts</h3>
8282
<p class="animated fadeInUp">You can use any of the following events:</p>
8383
</div>
8484
<ul>
85-
<li class="animated bounceInLeft"><em>slidetransitionend</em> (default, after the transition)</li>
86-
<li class="animated bounceInLeft"><em>slidechanged</em> (with the transition)</li>
87-
<li class="animated bounceInLeft"><em>auto</em> (with transition, on autoanimate slides)</li>
85+
<li class="animated fadeInLeft"><em>slidetransitionend</em> (default, after the transition)</li>
86+
<li class="animated fadeInLeft"><em>slidechanged</em> (with the transition)</li>
87+
<li class="animated fadeInLeft"><em>auto</em> (with transition, on autoanimate slides)</li>
8888
</ul>
8989
<div><br><small class="animated fadeInUp">This can also be set per-slide with data-attributes.</small></div>
9090
</section>
9191
</section>
92+
<section class="center" data-transition="convex-in fade-out" data-autoappear>
93+
<h3>Autoappear mode</h3><small>Sometimes (for example with Markdown), adding classes to elements is a chore. Appearance can automatically add animation classes to specific elements in the presentation (with the option <code>autoappear</code>) or per slide (with <code>data-autoappear</code>).</small>
94+
<ul>
95+
<li>This is list item 1</li>
96+
<li>This is list item 2</li>
97+
<li>This is list item 3</li>
98+
</ul>
99+
</section>
92100
<section class="center" data-transition="convex-in fade-out">
93-
<h3>Additional animations:</h3>
101+
<h3>Additional animations</h3>
94102
<ul>
95103
<li class="animated skidLeft" data-delay="300">Appear with .skidLeft</li>
96104
<li class="animated skidLeftBig" data-delay="1000">Appear with .skidLeftBig</li>
@@ -103,14 +111,14 @@ <h3>Additional animations:</h3>
103111
<section class="center" data-transition="fade-in">
104112
<h3>Thanks</h3>
105113
<ul>
106-
<li class="animated bounceInLeft">Hakim El Hattab for <a href="https://revealjs.com" target="_blank">Reveal.js</a></li>
107-
<li class="animated bounceInLeft">Daniel Eden for <a href="https://daneden.github.io/animate.css/" target="_blank">Animate.css</a></li>
108-
<li class="animated bounceInLeft">David Marby &amp; Nijiko Yonskai for <a href="https://picsum.photos" target="_blank">picsum.photos</a></li>
114+
<li class="animated fadeInLeft">Hakim El Hattab for <a href="https://revealjs.com" target="_blank">Reveal.js</a></li>
115+
<li class="animated fadeInLeft">Daniel Eden for <a href="https://daneden.github.io/animate.css/" target="_blank">Animate.css</a></li>
116+
<li class="animated fadeInLeft">David Marby &amp; Nijiko Yonskai for <a href="https://picsum.photos" target="_blank">picsum.photos</a></li>
109117
</ul>
110118
</section>
111119
</div>
112120
</div>
113-
<script src="https://cdn.jsdelivr.net/npm/reveal.js/dist/reveal.js"></script>
121+
<script src="../dist/reveal.js"></script>
114122
<script src="plugin/appearance/appearance.js"></script>
115123
<script>
116124
Reveal.initialize({
@@ -121,7 +129,13 @@ <h3>Thanks</h3>
121129
visibleclass: "in",
122130
hideagain: true,
123131
delay: 300,
124-
appearevent: "slidetransitionend"
132+
appearevent: "slidetransitionend",
133+
debug: true,
134+
autoappear: false,
135+
autoelements: {
136+
"ul li": "fadeInLeft",
137+
"ol li": "fadeInLeftRight"
138+
}
125139
},
126140
plugins: [
127141
Appearance

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "reveal.js-appearance",
33
"version": "1.1.0",
4-
"description": "A plugin for Reveal.js 4 that adds appearance effects to elements",
4+
"description": "A plugin for Reveal.js that adds appearance effects to elements",
55
"keywords": "reveal, reveal.js, reveal-plugin, plugin, text effects",
66
"homepage": "https://github.com/Martinomagnifico/reveal.js-appearance",
77
"repository": {

plugin/appearance/appearance.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@
2020
-webkit-perspective: 1000px;
2121
perspective: 1000px; }
2222

23+
small {
24+
margin: 1.5rem 0 2rem 0; }
25+
26+
small code {
27+
font-size: 75%;
28+
background: #222D2F;
29+
color: #ddd;
30+
padding: 0.25rem 0.5rem;
31+
border-radius: 0.5rem; }
32+
2333
/* Custom animation */
2434
@-webkit-keyframes skidLeft {
2535
from {

plugin/appearance/appearance.esm.js

Lines changed: 92 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,62 @@
1515
******************************************************************/
1616

1717

18+
function _slicedToArray(arr, i) {
19+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
20+
}
21+
22+
function _arrayWithHoles(arr) {
23+
if (Array.isArray(arr)) return arr;
24+
}
25+
26+
function _iterableToArrayLimit(arr, i) {
27+
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
28+
var _arr = [];
29+
var _n = true;
30+
var _d = false;
31+
var _e = undefined;
32+
33+
try {
34+
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
35+
_arr.push(_s.value);
36+
37+
if (i && _arr.length === i) break;
38+
}
39+
} catch (err) {
40+
_d = true;
41+
_e = err;
42+
} finally {
43+
try {
44+
if (!_n && _i["return"] != null) _i["return"]();
45+
} finally {
46+
if (_d) throw _e;
47+
}
48+
}
49+
50+
return _arr;
51+
}
52+
53+
function _unsupportedIterableToArray(o, minLen) {
54+
if (!o) return;
55+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
56+
var n = Object.prototype.toString.call(o).slice(8, -1);
57+
if (n === "Object" && o.constructor) n = o.constructor.name;
58+
if (n === "Map" || n === "Set") return Array.from(o);
59+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
60+
}
61+
62+
function _arrayLikeToArray(arr, len) {
63+
if (len == null || len > arr.length) len = arr.length;
64+
65+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
66+
67+
return arr2;
68+
}
69+
70+
function _nonIterableRest() {
71+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
72+
}
73+
1874
var Plugin = function Plugin() {
1975
// Scope support polyfill
2076
try {
@@ -100,6 +156,38 @@ var Plugin = function Plugin() {
100156
return selectionarray;
101157
};
102158

159+
var autoAdd = function autoAdd() {
160+
if (options.autoelements) {
161+
var _loop = function _loop() {
162+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
163+
autoelement = _Object$entries$_i[0],
164+
autoanimation = _Object$entries$_i[1];
165+
166+
if (options.autoappear) {
167+
debugLog("All \"".concat(autoelement, "\"\" elements will animate with ").concat(autoanimation));
168+
}
169+
170+
var autosection = options.autoappear ? "" : "[data-autoappear] ";
171+
var autoAppearances = deck.getRevealElement().querySelectorAll(".slides ".concat(autosection).concat(autoelement));
172+
173+
if (autoAppearances.length > 0) {
174+
autoAppearances.forEach(function (autoAppearance) {
175+
if (!autoAppearance.classList.contains(options.baseclass)) {
176+
autoAppearance.classList.add(options.baseclass);
177+
autoAppearance.classList.add(autoanimation);
178+
}
179+
});
180+
}
181+
};
182+
183+
for (var _i = 0, _Object$entries = Object.entries(options.autoelements); _i < _Object$entries.length; _i++) {
184+
_loop();
185+
}
186+
} else if (options.autoappear) {
187+
console.log("Please set an \"autoelements\" object.");
188+
}
189+
};
190+
103191
var showAppearances = function showAppearances(container) {
104192
clearTimeOuts(timeouts);
105193
var appearances = selectionArray(container, ":scope ." + options.baseclass);
@@ -190,6 +278,7 @@ var Plugin = function Plugin() {
190278
};
191279

192280
deck.on('ready', function (event) {
281+
autoAdd();
193282
showHideSlide(event);
194283
});
195284
deck.on('slidechanged', function (event) {
@@ -219,7 +308,9 @@ var Plugin = function Plugin() {
219308
hideagain: true,
220309
delay: 300,
221310
debug: false,
222-
appearevent: 'slidetransitionend'
311+
appearevent: 'slidetransitionend',
312+
autoappear: false,
313+
autoelements: null
223314
};
224315

225316
var defaults = function defaults(options, defaultOptions) {

0 commit comments

Comments
 (0)