Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div class="container">
    <video controls
        src="https://archive.org/download/BigBuckBunny_124/Content/big_buck_bunny_720p_surround.mp4"
        poster="https://peach.blender.org/wp-content/uploads/title_anouncement.jpg?x11217">

    Sorry, your browser doesn't support embedded videos, 
    but don't worry, you can <a href="https://archive.org/details/BigBuckBunny_124">download it</a> 
    and watch it with your favorite video player!

    </video>
    <aside data-target="notice"></aside>
    <button data-target="enter-pip" type="button" class="pure-button pure-button-primary">Enter PIP</button>

    <button data-target="exit-pip" type="button" class="pure-button">Exit PIP</button>
  </div>
              
            
!

CSS

              
                body {
  padding: 30px;
}

.container {
  width: 50%;
}

video {
  display: block;
  margin-bottom: 20px;
  width: 100%;
}

[data-target="pip"] {
  display: inline-block;
}

aside {
  background: #1f8dd6;
  margin: 1em 0;
  padding: 0.3em 1em;
  border-radius: 3px;
  color: #fff;
}
              
            
!

JS

              
                const isSupportPictureInPictureEnabled = "pictureInPictureEnabled" in document;
const videoElement = document.querySelector("video");
const enterPipButton = document.querySelector('[data-target="enter-pip"]');
const exitPipButton = document.querySelector('[data-target="exit-pip"]');
const notice = document.querySelector('[data-target="notice"]');

checkPipIsSupported();

enterPipButton.addEventListener("click", e => {
  e.preventDefault();
  // 觸發影片進入 PIP 模式
  videoElement.requestPictureInPicture().catch(error => {
    // Error Handling
    console.log({
      name: error.name,
      message: error.message
    });
  });
});

exitPipButton.addEventListener("click", e => {
  e.preventDefault();
  // 影片離開 PIP 模式
  document.exitPictureInPicture().catch(error => {
    // Error Handling
    console.log({
      name: error.name,
      message: error.message
    });
  });
});

/**
 * 事件
 **/
videoElement.addEventListener("enterpictureinpicture", () => {
  notice.textContent = "Enter Picture-in-Picture mode";
});

videoElement.addEventListener("leavepictureinpicture", () => {
  notice.textContent = "Exit Picture-in-Picture mode";
});

/**
 * 在 PIP 的視窗上增加前一部、後一部的功能鍵
 **/
navigator.mediaSession.setActionHandler("previoustrack", () => {
  // Go to previous track
});

navigator.mediaSession.setActionHandler("nexttrack", () => {
  // Go to next track
});

/**
 * 如果瀏覽器不支援 PIP
 **/
function checkPipIsSupported() {
  if (!isSupportPictureInPictureEnabled) {
    notice.textContent = "Picture In Picture is not supported.";

    enterPipButton.classList.add("hidden");
    enterPipButton.disabled = true;

    exitPipButton.classList.add("hidden");
    exitPipButton.disabled = true;
  } else {
    notice.textContent = "Picture In Picture is supported.";
  }
}

              
            
!
999px

Console