Add/Remove Slides from Reveal.JS dynamically

后端 未结 3 1138
悲哀的现实
悲哀的现实 2021-02-04 13:56

Is it possible to add/remove slides while a presentation is running with reveal.js? To be precise, is there an API for that or maybe some dirty workaround?

3条回答
  •  花落未央
    2021-02-04 14:42

    My workaround for this was to:

    1. Initialize reveal with an empty section tag.

      HTML

      Single Horizontal Slide

      Javascript

      Reveal.initialize();
      
      //slide deck wrapper
      deck = $('#blank').parent();
      
    2. Store this tag then remove it from the DOM.

      // a blank is initialized and stored as a variable
      wrap = $('#blank').clone()
                        .attr('id',null)
                        .prop('outerHTML');
      // remove the blank
      $('#blank').remove();
      
    3. Lastly a new element is added to deck and wrapped in the empty tag.

        $('

      Slide added

      ').appendTo(deck) .wrap( wrap );

    Here is a demo. I haven't tried this technique with any complicated configurations, but for a simple presentation this suffices.

提交回复
热议问题