Quick start¶
This page builds a stepped explainer from one video and a three-cue WebVTT
file. It uses the <vexy-vlip> Web Component, which needs no JavaScript of
your own.
Prerequisites¶
- A video file, here
demo.mp4. - A web server for the page. The player downloads the track with
fetch(), so opening the HTML file directly from disk (file://) may fail.
Steps¶
-
Create
demo.vttnext to the video:WEBVTT step-1 00:02.000 --> 00:03.500 This is a **plain-text** card near the bottom. step-2 00:04.000 --> 00:05.500 position:18% line:30% size:34% align:start A card placed top-left via native WebVTT cue settings. step-3 00:06.000 --> 00:07.500 { "text": "A JSON card with a custom backdrop.", "x": 50, "y": 50, "anchor": "center", "bg": "#10243a", "fg": "#eaf2ff", "radius": 16 }Each cue is one card.
step-1uses the default placement,step-2uses WebVTT cue settings, andstep-3is a JSON card with its own colours. -
Create
index.htmlthat loads the element build and places the player: -
Serve the folder, for example with
npx viteorpython3 -m http.server, and open the page. -
Click Start →. The video plays to 2 s, pauses, dims, and shows the first card. Click the card, the video, or Next →, or press Space, to play to the next card. After the last card the next advance plays to the end of the video, and a Replay ↻ button appears.
The same player from JavaScript¶
import { VexyVlip } from "vexy-vlip-js";
const stage = document.querySelector("#stage");
const vlip = new VexyVlip(stage, {
src: "demo.mp4",
track: "demo.vtt",
mode: "stepped", // "continuous" | "stepped"
controls: true,
});
// Methods can be called at once; the track loads asynchronously.
document.querySelector("#next").addEventListener("click", () => vlip.next());
// Events bubble from the container element.
stage.addEventListener("vexyvlip:stop", (e) => {
console.log("paused at segment", e.detail.index);
});
The container you pass to the constructor receives the class vexy-vlip, a
<video> element, and the card layer. If you pass an existing <video>
element instead, the player wraps it in a new <div> and uses that as the
container.
Inline tracks¶
Instead of a URL, pass the WebVTT text directly with the vtt option (or the
vtt attribute). The player then skips the network request:
Next steps¶
- Learn the full cue syntax in Authoring cards.
- Change colours and labels with Options and attributes or Theming.