|
15 | 15 | <!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
16 | 16 | <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
17 | 17 |
|
18 |
| - |
19 | 18 | - [Introduction](#introduction)
|
20 | 19 | - [Goals](#goals)
|
21 | 20 | - [Non-goals](#non-goals)
|
|
24 | 23 | - [HTML](#html)
|
25 | 24 | - [WebVTT](#webvtt)
|
26 | 25 | - [Cue Fragments](#cue-fragments)
|
| 26 | +- [Using the API and styling cues](#using-the-api-and-styling-cues) |
27 | 27 | - [Considered alternatives](#considered-alternatives)
|
28 | 28 | - [Abstract Data Model](#abstract-data-model)
|
29 | 29 | - [Stakeholder Signals](#stakeholder-signals)
|
@@ -168,6 +168,50 @@ Here are some simple examples:
|
168 | 168 | <div cuebackground cue>This is a <b>simple</b> cue.</div>
|
169 | 169 | ```
|
170 | 170 |
|
| 171 | +## Using the API and styling cues |
| 172 | + |
| 173 | +It is expected that the API will be used as follows: |
| 174 | + |
| 175 | +```js |
| 176 | +// Get a reference to a video element. |
| 177 | +const videoElement = document.getElementById("someVideoElement"); |
| 178 | + |
| 179 | +// Create a new text track. |
| 180 | +const textTrack = videoElement.addTextTrack("captions", "English", "en"); |
| 181 | +textTrack.mode = "showing"; |
| 182 | + |
| 183 | +// Create a new cue fragment. |
| 184 | +const cueFragment = new DocumentFragment(); |
| 185 | +const div = document.createElement("div"); |
| 186 | +div.cuebackground = true; |
| 187 | +div.innerHTML = "This is a <span cue class='important'>cue</span>."; |
| 188 | +cueFragment.appendChild(div); |
| 189 | +const cue = new TextTrackCue(0, 30, cueFragment); |
| 190 | + |
| 191 | +// Now add the cue to the text track. |
| 192 | +textTrack.addCue(cue); |
| 193 | +``` |
| 194 | + |
| 195 | +And then the `::cue` and ::`cuebackground` pseudo-elements can be used |
| 196 | +to style the text track cue: |
| 197 | + |
| 198 | +```css |
| 199 | +::cue { |
| 200 | + color: white; |
| 201 | + font-size: 1.5em; |
| 202 | + font-weight: bold; |
| 203 | +} |
| 204 | + |
| 205 | +::cue.important { |
| 206 | + border: 1px solid red; |
| 207 | +} |
| 208 | + |
| 209 | +::cuebackground { |
| 210 | + background-color: black; |
| 211 | + opacity: 0.5; |
| 212 | +} |
| 213 | +``` |
| 214 | + |
171 | 215 | ## Considered alternatives
|
172 | 216 |
|
173 | 217 | ### Abstract Data Model
|
|
0 commit comments