【问题标题】:Can you "end" a reveal.js presentation?你能“结束”一个reveal.js 演示文稿吗?
【发布时间】:2016-04-14 01:58:05
【问题描述】:

我正在寻找Reveal.initialize() 的对应物/相反物。一种以编程方式结束reveal.js 演示文稿的方法。

【问题讨论】:

  • 你能分享一下你到底在找什么吗?
  • 你能不能只隐藏 Reveal.js 容器?

标签: reveal.js


【解决方案1】:

Reveal.js 没有实现以编程方式结束演示的方法。 Here is the list of methods available.

如果您正在寻找销毁 Reveal.js 的实例,除非 Reveal.js 团队实现它,否则这是不可能的。您可以做的是,您可以删除初始化 Reveal 事件的 DOM 元素。

这是您可以使用它来销毁 Reveal.js 演示文稿的所有/任何实例的代码。

Element.prototype.remove = function() {
    this.parentElement.removeChild(this);
}
NodeList.prototype.remove = HTMLCollection.prototype.remove = function() {
    for(var i = this.length - 1; i >= 0; i--) {
        if(this[i] && this[i].parentElement) {
            this[i].parentElement.removeChild(this[i]);
        }
    }
}

document.querySelectorAll('.reveal').remove();

//To remove all containers created by Math Plugin    
var mathPluginContainers = document.querySelectorAll("[id^='MathJax']");
mathPluginContainers = Array.prototype.slice.call(mathPluginContainers);
var mathPluginParents = mathPluginContainers.map(function(container) { 
    return container.parentElement;
});

mathPluginParents.forEach(function (container, index) {
    if (container.tagName === 'DIV') {
        container.remove();
    } else {
        container.removeChild(mathPluginContainers[index]);
    }
});

【讨论】:

    【解决方案2】:

    在开始演示之前,您可以创建 DOM 树副本 (1),然后在需要时恢复它 (2)。

    // (1) create DOM copy
    window.saved = document.body.cloneNode(true);
    
    Reveal.initialize({
      // initialisation parameters
    });
    
    // (2) restore DOM to previous state
    document.body.parentNode.replaceChild(window.saved, document.body)
    

    它正在停止演示并且没有出错。唯一的问题可能是必须做一些额外的事情才能重新开始演示。

    【讨论】:

      猜你喜欢
      • 2015-09-18
      • 1970-01-01
      • 1970-01-01
      • 2017-03-15
      • 1970-01-01
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      • 2015-11-17
      相关资源
      最近更新 更多