test-auto-animate.html 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. h1: slide.querySelector( 'h1' ),
  40. h2: slide.querySelector( 'h2' ),
  41. h3: slide.querySelector( 'h3' )
  42. };
  43. } );
  44. Reveal.addEventListener( 'ready', () => {
  45. QUnit.module( 'Auto-Animate' );
  46. QUnit.test( 'Adds data-auto-animate-target', assert => {
  47. Reveal.slide(1);
  48. assert.strictEqual( slides[0].h1.getAttribute( 'data-auto-animate-target' ), '', 'From elements have blank data-auto-animate-target' );
  49. assert.ok( slides[1].h1.getAttribute( 'data-auto-animate-target' ).length > 0, 'To elements have a data-auto-animate-target value' );
  50. });
  51. QUnit.test( 'Ends on correct target styles', assert => {
  52. Reveal.slide(1);
  53. assert.strictEqual( slides[1].h2.style.opacity, "0" );
  54. assert.strictEqual( slides[1].h3.offsetLeft, 100 );
  55. });
  56. QUnit.test( 'Slide specific data-auto-animate-duration', assert => {
  57. assert.timeout( 400 );
  58. let done = assert.async();
  59. let callback = () => {
  60. slides[2].h3.removeEventListener( 'transitionend', callback );
  61. assert.ok( true, 'Transition ended within time window' );
  62. done();
  63. }
  64. Reveal.slide(2);
  65. slides[2].h3.addEventListener( 'transitionend', callback );
  66. });
  67. QUnit.test( 'Element specific data-auto-animate-duration', assert => {
  68. assert.timeout( 400 );
  69. let done = assert.async();
  70. let callback = () => {
  71. slides[1].h1.removeEventListener( 'transitionend', callback );
  72. assert.ok( true, 'Transition ended within time window' );
  73. done();
  74. }
  75. Reveal.slide(1);
  76. slides[1].h1.addEventListener( 'transitionend', callback );
  77. });
  78. } );
  79. Reveal.initialize();
  80. </script>
  81. </body>
  82. </html>