← All examples

JavaScript Media vimeo.com

Vimeo: picture-in-picture button

Adds a floating button that opens the current video in picture-in-picture mode and closes it again.

Code to copy

// Add a floating button that opens the video in picture-in-picture
function addPipButton() {
  if (document.getElementById('jz-vmo-pip')) return;
  const v = document.querySelector('video');
  if (!v) return;
  const b = document.createElement('button');
  b.id = 'jz-vmo-pip';
  b.textContent = 'PiP';
  b.style.cssText = 'position:fixed;bottom:14px;right:14px;z-index:99999;background:#00adef;color:#fff;border:0;border-radius:6px;padding:8px 12px;font:13px sans-serif;cursor:pointer;';
  b.addEventListener('click', function () {
    const vid = document.querySelector('video');
    if (vid && document.pictureInPictureEnabled) {
      if (document.pictureInPictureElement) { document.exitPictureInPicture(); }
      else { vid.requestPictureInPicture().catch(function () {}); }
    }
  });
  document.body.appendChild(b);
}
addPipButton();
const obs = new MutationObserver(addPipButton);
obs.observe(document.documentElement, { childList: true, subtree: true });

How to use this example

  1. Copy the code with the button above.
  2. Install JustZix (2 minutes) and open the extension on the target page.
  3. Add a new rule matching that page.
  4. Paste the code into the rule's JavaScript panel and save — it runs on every page visit.

Rate this example

No ratings yet — be the first.

Does this example work?

Snippets are useless without somewhere to paste them.

JustZix takes 2 minutes to install and runs your code on every matching page. No account, no payment.

Download free See use cases