videojs-story-view

Instagram-style stories for the web. A small <story-view> custom element with no dependencies, and a plugin for Video.js 8.

Waiting for the first story…

npm install videojs-story-view
Mountains and a forest by a lake A waterfall in a green forest Sunlight over a misty valley

Just HTML

Put <img> and <video> elements inside <story-view>. Each one becomes a story. data-* attributes set the header, the duration and a link.

<script src="https://cdn.jsdelivr.net/npm/videojs-story-view@1"></script>

<story-view image-duration="4">
  <img src="lake.jpg" alt="A lake" data-title="Andrew Ridley">
  <video src="clip.mp4" preload="none" data-duration="8"></video>
  <img src="valley.jpg" alt="A valley"
       data-link="https://example.com" data-link-label="Read more">
</story-view>

Video.js 8 plugin

player.storyView() plays each video story through your Video.js 8 player, so its tech, HLS and DASH support and plugins all apply. Image stories are drawn on top.

import videojs from 'video.js';
import { registerStoryView } from 'videojs-story-view/videojs';

registerStoryView(videojs);

const player = videojs('my-player', { aspectRatio: '9:16' });
const stories = player.storyView({ items, loop: true });
stories.on('storychange', ({ index }) => console.log(index));

Video.js 10, or any media element

Video.js 10 has no plugin system; you compose elements instead. Put <story-view> inside the player's container and point media at the media element. The story view sets its src and drives playback; the Video.js store sees every change. The same works with a plain <video>.

<video-player>
  <media-container>
    <video id="media" playsinline muted></video>
    <story-view media="media">…</story-view>
  </media-container>
</video-player>
Gradient bars
Card
Right to left

Theming

Change colors and sizes with CSS custom properties, or reach any piece with ::part(). Right-to-left pages get mirrored taps, swipes and arrow keys.

story-view {
  --story-view-accent: linear-gradient(90deg, #f9ce34, #ee2a7b, #6228d7);
  --story-view-segment-height: 4px;
  --story-view-radius: 24px;
}

story-view::part(title) {
  font-weight: 700;
}