我正在寻找Reveal.initialize()
的对应/对面。一种以编程方式结束reveal.js演示文稿的方法。
答案 0 :(得分:4)
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]);
}
});
答案 1 :(得分:0)
在开始演示之前,您可以创建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)
它正在停止演示而不会出现任何错误。唯一的问题可能是需要做一些额外的事情才能再次启动演示文稿。