test-auto-animate.html 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>reveal.js - Test Auto-Animate</title>
  6. <link rel="stylesheet" href="../css/reveal.css">
  7. <link rel="stylesheet" href="qunit-2.5.0.css">
  8. </head>
  9. <body style="overflow: auto;">
  10. <div id="qunit"></div>
  11. <div id="qunit-fixture"></div>
  12. <div class="reveal">
  13. <div class="slides">
  14. <section data-auto-animate>
  15. <h1>h1</h1>
  16. <h2>h2</h2>
  17. <h3 style="position: absolute; left: 0;">h3</h2>
  18. </section>
  19. <section data-auto-animate>
  20. <h1 data-auto-animate-duration="0.3">h1</h1>
  21. <h2 style="opacity: 0;">h2</h2>
  22. <h3 style="position: absolute; left: 100px;">h3</h2>
  23. </section>
  24. <section data-auto-animate data-auto-animate-duration="0.3">
  25. <h1>h1</h1>
  26. <h2>h2</h2>
  27. <h3>h3</h2>
  28. </section>
  29. <section>
  30. <h1>Non-auto-animate slide</h1>
  31. </section>
  32. </div>
  33. </div>
  34. <script src="../js/reveal.js"></script>
  35. <script src="qunit-2.5.0.js"></script>
  36. <script>
  37. const slides = Array.prototype.map.call( document.querySelectorAll( '.slides section' ), slide => {
  38. return {
  39. slide: slide,
  40. h1: slide.querySelector( 'h1' ),
  41. h2: slide.querySelector( 'h2' ),
  42. h3: slide.querySelector( 'h3' )
  43. };
  44. } );
  45. Reveal.addEventListener( 'ready', () => {
  46. QUnit.module( 'Auto-Animate' );
  47. QUnit.test( 'Adds data-auto-animate-target', assert => {
  48. Reveal.slide(1);
  49. assert.strictEqual( slides[0].h1.getAttribute( 'data-auto-animate-target' ), '', 'From elements have blank data-auto-animate-target' );
  50. assert.ok( slides[1].h1.getAttribute( 'data-auto-animate-target' ).length > 0, 'To elements have a data-auto-animate-target value' );
  51. });
  52. QUnit.test( 'Ends on correct target styles', assert => {
  53. Reveal.slide(1);
  54. assert.strictEqual( slides[1].h2.style.opacity, "0" );
  55. assert.strictEqual( slides[1].h3.offsetLeft, 100 );
  56. });
  57. QUnit.test( 'Slide specific data-auto-animate-duration', assert => {
  58. assert.timeout( 400 );
  59. let done = assert.async();
  60. let callback = () => {
  61. slides[2].h3.removeEventListener( 'transitionend', callback );
  62. assert.ok( true, 'Transition ended within time window' );
  63. done();
  64. }
  65. Reveal.slide(2);
  66. slides[2].h3.addEventListener( 'transitionend', callback );
  67. });
  68. QUnit.test( 'Element specific data-auto-animate-duration', assert => {
  69. assert.timeout( 400 );
  70. let done = assert.async();
  71. let callback = () => {
  72. slides[1].h1.removeEventListener( 'transitionend', callback );
  73. assert.ok( true, 'Transition ended within time window' );
  74. done();
  75. }
  76. Reveal.slide(1);
  77. slides[1].h1.addEventListener( 'transitionend', callback );
  78. });
  79. QUnit.test( 'Does not add [data-auto-animate] on non auto-animated slides', assert => {
  80. Reveal.slide(2);
  81. Reveal.next();
  82. assert.ok( slides[3].slide.hasAttribute( 'data-auto-animate' ) === false )
  83. });
  84. QUnit.test( 'autoAnimate config option', assert => {
  85. Reveal.configure({ autoAnimate: false });
  86. assert.ok( document.querySelectorAll( 'data-auto-animate-target' ).length === 0, 'Removes all [data-auto-animate-target]' )
  87. assert.ok( Array.prototype.every.call( document.querySelectorAll( 'section[data-auto-animate]' ), el => {
  88. return el.dataset.autoAnimate === '';
  89. }, 'All data-auto-animate attributes are reset' ) );
  90. Reveal.configure({ autoAnimate: true });
  91. });
  92. } );
  93. Reveal.initialize();
  94. </script>
  95. </body>
  96. </html>