Skip to content

Commit 1d57bbb

Browse files
TextTracks: add examples (#107)
1 parent 6076dea commit 1d57bbb

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

texttracks/README.md

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
1616
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
1717

18-
1918
- [Introduction](#introduction)
2019
- [Goals](#goals)
2120
- [Non-goals](#non-goals)
@@ -24,6 +23,7 @@
2423
- [HTML](#html)
2524
- [WebVTT](#webvtt)
2625
- [Cue Fragments](#cue-fragments)
26+
- [Using the API and styling cues](#using-the-api-and-styling-cues)
2727
- [Considered alternatives](#considered-alternatives)
2828
- [Abstract Data Model](#abstract-data-model)
2929
- [Stakeholder Signals](#stakeholder-signals)
@@ -168,6 +168,50 @@ Here are some simple examples:
168168
<div cuebackground cue>This is a <b>simple</b> cue.</div>
169169
```
170170

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+
171215
## Considered alternatives
172216

173217
### Abstract Data Model

0 commit comments

Comments
 (0)