polite-media

The still above was replaced by video on the frame that actually painted, after the page finished loading, and it stops when you scroll away.

Background video, image reveals and next-page image warming. No dependencies, no framework, about 4 KB gzipped for the video half.

It doesn't flash, doesn't hog the decoder, doesn't eat data on a metered connection, doesn't ignore reduced motion, and doesn't autoplay without giving anyone a way to stop it.

Install

npm install polite-media

The whole thing

<div class="your-own-box" data-polite-media>
  <img src="poster.avif" alt="" />
  <video muted loop playsinline preload="none" tabindex="-1" aria-hidden="true">
    <source src="hero.mp4" type="video/mp4" />
  </video>
</div>

<button type="button" data-polite-pause-control aria-pressed="false">
  Pause background video
</button>
import { register } from 'polite-media/video';
import 'polite-media/video.css';

register(document.querySelector('[data-polite-media] video'));

What that bought you

See it break, on purpose

Sixteen pages covering the awkward cases: grids that arbitrate between videos, art-directed posters, codec fallback, save-data, no-JS, and the reveal failsafe.

Browse the demos →