近日有文章详细介绍了如何在网页端实现电视广播中常见的“squeezeback”效果,即在视频播放时将画面缩小并腾出空间展示赞助商卡片、第二视角或表单等内容 1。作者利用 Video.js v10 和 WebVTT 文本轨道作为时间线调度系统,实现了无需轮询的布局动画 1。
在具体技术实现上,该效果通过 3×3 CSS Grid 布局实现,中心单元格放置视频播放器,外部轨道从 0fr 动画展开以显示附加面板 1。系统使用 WebVTT 文本轨道的 cue 作为时间线调度系统,通过 cuechange 事件触发布局变化,无需轮询 currentTime 1。Video.js v10 的 usePlayer 提供 selectTextTrack 订阅文本轨道状态变化,文本轨道使用 hidden 模式解析 cue 并触发事件但不渲染字幕 1。
文章还讨论了 CSS 动画插值、@property 注册、Canvas 取色等实现细节与注意事项 1。例如,hls.js 会在 attach 时清除所有文本轨道的 cues,需通过 track 元素重新加载修复 1。在 CSS 动画插值方面,CSS Grid fr 值插值要求模板总值匹配,否则动画会出现非线性问题 1。@property 注册的 initial-value 必须计算独立,不能使用 rem、em 或百分比,需使用绝对像素值如 32px 1。Canvas 取色实现环境光效果需要 crossOrigin="anonymous" 和 CORS 头支持,且仅适用于未加密内容 1。此外,表单字段获得焦点时冻结布局动画,防止 cue 过期导致输入中断 1。
An article details how to implement the "squeezeback" effect, commonly seen in television broadcasting, on web pages using CSS Grid and WebVTT 1. This effect shrinks the video playback area to make room for displaying sponsor cards, secondary camera angles, or forms 1. The implementation utilizes a 3x3 CSS Grid layout, placing the video player in the center cell while animating the outer tracks from 0fr to reveal the additional panels 1.
To achieve layout animations without polling currentTime, the author employs WebVTT text track cues as a timeline scheduling system, triggering layout changes via cuechange events 1. Within Video.js v10, usePlayer provides selectTextTrack to subscribe to text track state changes, and the text tracks use a hidden mode to parse cues and trigger events without rendering subtitles 1. The author also notes that CSS Grid fr value interpolation requires the total template values to match to prevent non-linear animation issues, and the initial-value registered with @property must be calculated independently using absolute pixel values like 32px instead of relative units like rem, em, or percentages 1.
Regarding ambient lighting effects, implementing color extraction via Canvas requires crossOrigin="anonymous" and CORS header support, and it is only applicable to unencrypted content 1. Addressing specific interactions and library limitations, the author mentions that layout animations are frozen when form fields receive focus to prevent input interruption caused by expired cues 1. Furthermore, because hls.js clears all text track cues upon attaching, the issue must be fixed by reloading through the <track> element 1.
评论
还没有评论,欢迎留下第一条。