返回 reveal.js
test-auto-animate.html
根目录 / test / test-auto-animate.html
1 <!doctype html>
2 <html lang="en">
3
4 <head>
5 <meta charset="utf-8">
6
7 <title>reveal.js - Test Auto-Animate</title>
8 </head>
9
10 <body style="overflow: auto;">
11
12 <div id="qunit"></div>
13 <div id="qunit-fixture"></div>
14
15 <div class="reveal">
16
17 <div class="slides">
18
19 <section data-auto-animate>
20 <h1>h1</h1>
21 <h2>h2</h2>
22 <h3 style="position: absolute; left: 0;">h3</h3>
23 </section>
24
25 <section data-auto-animate>
26 <h1 data-auto-animate-duration="0.1">h1</h1>
27 <h2 style="opacity: 0;">h2</h2>
28 <h3 style="position: absolute; left: 100px;">h3</h3>
29 </section>
30
31 <section data-auto-animate data-auto-animate-duration="0.1">
32 <h1>h1</h1>
33 <h2>h2</h2>
34 <h3>h3</h3>
35 </section>
36
37 <section>
38 <h1>Non-auto-animate slide</h1>
39 </section>
40
41 <section data-auto-animate>
42 <h1 class="fragment">h1</h1>
43 <h2 class="fragment">h2</h2>
44 <h3>h3</h3>
45 </section>
46
47 <section data-auto-animate>
48 <h1 class="fragment">h1</h1>
49 <h2 class="fragment">h2</h2>
50 <h3 class="fragment">h3</h3>
51 </section>
52
53 <section>
54 <h1>Non-auto-animate slide</h1>
55 </section>
56
57 </div>
58
59 </div>
60
61 <script type="module">
62 import 'reveal.css';
63 import 'qunit/qunit/qunit.css';
64 import QUnit from 'qunit';
65 import Reveal from 'reveal.js';
66
67 QUnit.config.testTimeout = 30000;
68 QUnit.config.reorder = false;
69 QUnit.config.autostart = false;
70
71 const slides = Array.prototype.map.call( document.querySelectorAll( '.slides section' ), slide => {
72 return {
73 slide: slide,
74 h1: slide.querySelector( 'h1' ),
75 h2: slide.querySelector( 'h2' ),
76 h3: slide.querySelector( 'h3' )
77 };
78 } );
79
80 QUnit.module( 'Auto-Animate' );
81
82 Reveal.initialize().then( () => {
83
84 QUnit.start();
85
86 QUnit.test( 'Adds data-auto-animate-target', assert => {
87 Reveal.slide(1);
88 assert.strictEqual( slides[0].h1.getAttribute( 'data-auto-animate-target' ), '', 'From elements have blank data-auto-animate-target' );
89 assert.ok( slides[1].h1.getAttribute( 'data-auto-animate-target' ).length > 0, 'To elements have a data-auto-animate-target value' );
90 });
91
92 QUnit.test( 'Ends on correct target styles', assert => {
93 Reveal.slide(1);
94 assert.strictEqual( slides[1].h2.style.opacity, "0" );
95 assert.strictEqual( slides[1].h3.offsetLeft, 100 );
96 });
97
98 QUnit.test( 'Does not add [data-auto-animate] on non auto-animated slides', assert => {
99 Reveal.slide(2);
100 Reveal.next();
101 assert.ok( slides[3].slide.hasAttribute( 'data-auto-animate' ) === false )
102 });
103
104 QUnit.test( 'autoAnimate config option', assert => {
105 Reveal.configure({ autoAnimate: false });
106
107 assert.ok( document.querySelectorAll( 'data-auto-animate-target' ).length === 0, 'Removes all [data-auto-animate-target]' )
108 assert.ok( Array.prototype.every.call( document.querySelectorAll( 'section[data-auto-animate]' ), el => {
109 return el.dataset.autoAnimate === '';
110 }, 'All data-auto-animate attributes are reset' ) );
111
112 Reveal.configure({ autoAnimate: true });
113 });
114
115 QUnit.test( 'Slide specific data-auto-animate-duration', assert => {
116 assert.timeout( 2000 );
117 assert.expect( 1 );
118
119 return new Promise( resolve => {
120 let callback = () => {
121 slides[2].h3.removeEventListener( 'transitionend', callback );
122 assert.ok( true, 'Transition ended within time window' );
123 resolve();
124 }
125
126 Reveal.slide(1);
127 Reveal.slide(2);
128
129 slides[2].h3.addEventListener( 'transitionend', callback );
130 } );
131 });
132
133 // QUnit.test( 'Element specific data-auto-animate-duration', assert => {
134 // assert.timeout( 400 );
135 // assert.expect( 1 );
136
137 // return new Promise( resolve => {
138 // let callback = () => {
139 // slides[1].h1.removeEventListener( 'transitionend', callback );
140 // assert.ok( true, 'Transition ended within time window' );
141 // resolve()
142 // }
143
144
145 // Reveal.slide(1);
146 // slides[1].h1.addEventListener( 'transitionend', callback );
147 // } );
148 // });
149
150 } );
151 </script>
152
153 </body>
154 </html>
155
155 lines HTML