Picture-in-picture for any element

One call, pipElement(el), puts any element in a window above your other windows. It can be a timer, a table or one button. Choose how, then press Float on a specimen, or Pick any element and click anything on this page.

How

Nothing is floating.

<div> widget
<form>
<table>
Lap1
This lap0.0 s
Best–
<button>
<svg>
<p>

The fog comes on little cat feet. It sits looking over harbor and city on silent haunches and then moves on.

Show the code float any element
  1. One call. el is any element, mode() is the radio button above, and media maps media keys to buttons inside the element (optional).
  2. Inside, mode "move": the real element goes into a Document Picture-in-Picture window. No canvas at all. The start of this branch is shown.
  3. Inside, mode "stream": the element stays, a live picture of it floats, and input comes back. This is where HTML-in-canvas comes in: the element is drawn into a canvas and the pixels are served to the window.
  4. Inside, mode "video": the canvas becomes a MediaStream in a <video>, which classic Picture-in-Picture accepts.
  5. How the element gets into a canvas.
  6. The whole library.

The three ways

import { pipElement } from '/lib/element-pip.js';
const pip = await pipElement(el, { mode: 'move' | 'stream' | 'video' | 'auto' });
pip.close();  await pip.closed;   // el also fires 'enterpip' and 'leavepip'

Live checks

ResultExperimentDetail