控制器系统是 reveal.js 的架构骨干,它提供了管理演示框架特定方面的专用模块。每个控制器负责一个特定的功能或行为,从而实现模块化和可维护的代码库。本文档介绍了控制器架构、生命周期以及为 reveal.js 演示提供支持的关键控制器。
有关与这些控制器交互的主 API 的信息,请参阅 Reveal.js 主 API。有关事件如何流经系统的详细信息,请参阅 事件处理。
reveal.js 演示框架使用基于控制器的模块化架构。每个控制器都由主 Reveal 对象实例化,并管理演示的特定方面。
来源:js/reveal.js105-126 js/controllers/slidecontent.js10-500 js/controllers/keyboard.js6-414 js/controllers/autoanimate.js11-626 js/controllers/backgrounds.js7-470 js/controllers/fragments.js8-374 js/controllers/controls.js17-286 js/controllers/overview.js8-254 js/controllers/progress.js4-109
reveal.js 中的控制器遵循一致的生命周期模式。
来源:js/reveal.js131-168 js/reveal.js558-601 js/reveal.js607-667
控制器在 Reveal.js 初始化过程中被实例化。每个控制器都会接收到对主 Reveal 实例的引用,使它们能够在需要时访问配置设置和其他控制器。
reveal.js 框架包含许多控制器,每个控制器负责演示的特定方面。以下是最重要的控制器及其职责。
SlideContent 控制器负责加载、卸载和播放幻灯片内容,如图像、视频和 iframe。
主要职责
关键方法
load(slide, options):为幻灯片加载内容unload(slide):从幻灯片卸载内容startEmbeddedContent(element):启动嵌入式媒体播放stopEmbeddedContent(element, options):停止嵌入式媒体播放来源:js/controllers/slidecontent.js10-500
Backgrounds 控制器创建和管理幻灯片背景,包括图像、视频和纯色背景。
主要职责
关键方法
render():创建背景容器create():为所有幻灯片创建背景元素sync(slide):根据幻灯片属性更新其背景update(includeAll):根据当前幻灯片更新背景可见性updateParallax():更新视差背景的位置来源:js/controllers/backgrounds.js7-470
Keyboard 控制器处理演示的所有键盘交互。
主要职责
关键方法
configure(config, oldConfig):根据配置更新键盘快捷方式bind():开始监听键盘事件unbind():停止监听键盘事件addKeyBinding(binding, callback):添加自定义按键绑定removeKeyBinding(keyCode):删除自定义按键绑定triggerKey(keyCode):以编程方式触发键盘事件来源:js/controllers/keyboard.js6-414
Controls 控制器管理演示中显示的导航箭头控件。
主要职责
关键方法
render():创建控件元素bind():将事件监听器附加到控件unbind():从控件移除事件监听器update():更新控件状态(启用/禁用)来源:js/controllers/controls.js17-286
Fragments 控制器负责管理幻灯片内分步显示的片段(fragments)的显示和导航。
主要职责
关键方法
sort(fragments, grouped):按索引排序片段update(index, fragments, slide):更新片段可见性next():前进到下一个片段prev():移到上一个片段来源:js/controllers/fragments.js8-374
AutoAnimate 控制器提供匹配元素之间的幻灯片自动动画。
主要职责
关键方法
run(fromSlide, toSlide):启动幻灯片之间的动画reset():清除任何活动的动画getAutoAnimatableElements(fromSlide, toSlide):查找匹配的元素autoAnimateElements(from, to, elementOptions, animationOptions, id):在两个元素之间进行动画来源:js/controllers/autoanimate.js11-626
Overview 控制器管理概览模式,该模式显示所有幻灯片的鸟瞰图。
主要职责
关键方法
activate():进入概览模式deactivate():退出概览模式toggle(override):切换概览模式update():更新概览显示来源: js/controllers/overview.js8-254
The Progress controller creates and updates the progress bar for the presentation.
主要职责
关键方法
render(): Creates the progress elementsupdate(): Updates the progress bar based on current slideonProgressClicked(event): Handles navigation when the progress bar is clicked来源: js/controllers/progress.js4-109
The Pointer controller manages mouse pointer visibility and mouse wheel navigation.
主要职责
关键方法
showCursor(): Makes the cursor visiblehideCursor(): Hides the cursoronDocumentMouseScroll(event): Handles mouse wheel navigation来源: js/controllers/pointer.js4-126
Controllers often interact with each other to provide coordinated functionality. Below is a diagram showing key relationships between controllers
来源: js/reveal.js105-126 js/reveal.js542-551 js/controllers/backgrounds.js362-367
While most interaction with controllers happens through the main Reveal.js API, you can access controllers directly through the Reveal instance for advanced use cases.
来源: js/index.js13-56
Controllers are configured through the main Reveal configuration object. Many controllers have dedicated configuration options that modify their behavior.
The controller architecture of reveal.js makes it extensible. You can create custom controllers to add new functionality to your presentations.
A custom controller typically follows this pattern
The modular controller architecture makes reveal.js highly extensible and maintainable, allowing each controller to focus on a specific aspect of the presentation framework.
刷新此 Wiki
最后索引时间2025 年 4 月 18 日(dfc569)