Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

Behavior

Save Automatically?

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

              
                <!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <title>Under the Hood: Video Player</title>
  <link rel="stylesheet" href="style.css">
  <link rel="icon" type="image/png" href="../favicon.png">
</head>

<body>
  <div class="app">
    <div class="app__title">Use Inspector Mode to focus on a specific component!</div>
    <div class="player">
      <video class="player__video viewer" src="https://player.vimeo.com/external/194837908.sd.mp4?s=c350076905b78c67f74d7ee39fdb4fef01d12420&profile_id=164"></video>

      <div class="player__controls">
        <div class="progress">
          <div class="progress__filled"></div>
        </div>
        <button class="player__button toggle" title="Toggle Play">►</button>
        <input type="range" name="volume" class="player__slider" min="0" max="1" step="0.05" value="1">
        <input type="range" name="playbackRate" class="player__slider" min="0.5" max="2" step="0.1" value="1">
        <button data-skip="-10" class="player__button">« 10s</button>
        <button data-skip="25" class="player__button">25s »</button>
      </div>
    </div>

    <div class="inspector">
      <div class="inspector__title">
        <div class="inspector__current-item--title">Focusing on
          <span class="inspector__current-item"></span>
        </div>
        <div class="inspector__button--inspector off"></div>
        <div class="inspector__button--clear">Clear Focus</div>
      </div>
      <div class="inspector__window"></div>
    </div>
  </div>
  <script src="player.js"></script>
</body>

</html>
              
            
!

CSS

              
                html {
  box-sizing: border-box;
  --hl-blue: rgba(60, 200, 219, 0.5);
  --hl-orange: rgba(238, 150, 75, 0.5);
  --hl-yellow: rgba(244, 211, 95, 0.5);
  --hl-white: rgba(255, 255, 255, 0.25);
  --solid-blue: #209bf3;
  --solid-goldenrod: #d9a902;
  --solid-gray: #ddd;
  --solid-green: #9bd763;
  --solid-orange: #f45d01;
  --solid-pink: #ff548d;
  --solid-red: red;
  --inspector-bg: #eee;

  font-size: 12px;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  align-content: center;
  flex-flow: row wrap;
  font-family: 'Inconsolata', monospace;
  background: #7a419b;
  min-height: 100vh;
  background: linear-gradient(215deg, #fc789a 0%, #fc4675 48%, #cf3a60 100%);
  background-size: cover;
  justify-content: center;
}

.app {
  display: flex;
  flex-flow: row wrap;
  align-items: center;
  justify-content: center;
  height: 80%;
  padding-bottom: 5vmax;
}

.app__title {
  position: relative;
  display: flex;
  align-items: center;
  align-self: flex-end;
  background: var(--hl-white);
  border-radius: 5px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
  color: #222;
  flex-basis: 100%;
  flex-flow: row nowrap;
  font-size: 1.5rem;
  justify-content: center;
  padding: 1rem;
}

.app__title.hidden {
  display: none;
}

.inspector {
  display: flex;
  border: 5px solid transparent;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
  flex-basis: calc(500px + 10vw);
  flex-flow: column nowrap;
  align-content: center;
  align-items: center;
  align-self: flex-start;
  justify-content: center;
  margin-top: 1rem;
}
.inspector__title {
  display: flex;
  align-items: center;
  background: var(--inspector-bg);
  border-radius: 5px 5px 0 0;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
  color: #222;
  flex-basis: 4rem;
  flex-flow: row nowrap;
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  padding: 0 1rem;
  width: calc(500px + 10vw);
}
.inspector__current-item {
  font-weight: bold;
}
.inspector__current-item--title {
  flex-grow: 3;
}
.inspector__button--inspector {
  background: var(--solid-blue);
  border: 1px solid transparent;
  border-radius: 5px;
  color: white;
  cursor: pointer;
  flex-grow: 1;
  font-size: 1.25rem;
  padding: 0.5rem;
  text-align: center;
}
.inspector__button--inspector::before {
  content: 'Inspector Mode: On';
}
.inspector__button--inspector.off {
  background: var(--solid-red);
}
.inspector__button--inspector.off::before {
  content: 'Inspector Mode: Off';
}
.inspector__button--clear {
  border: 1px solid #ccc;
  border-radius: 5px;
  color: #222;
  cursor: pointer;
  flex-grow: 0.25;
  font-size: 1.25rem;
  margin-left: 0.25rem;
  padding: 0.5rem;
  text-align: center;
}
.inspector__window {
  background: var(--inspector-bg);
  border-radius: 0 0 5px 5px;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
  color: #222;
  flex-basis: 100%;
  font-size: 1.5rem;
  overflow-x: wrap;
  overflow-y: scroll;
  padding: 0 1rem 0 0;
  position: relative;
  width: calc(500px + 10vw);
}
/* .inspector__window::-webkit-scrollbar {
  display: none;
} */

.player {
  align-self: flex-start;
  border: 5px solid transparent;
  box-shadow: 0 0 20px rgba(0, 0, 0, 0.2);
  font-size: 0;
  flex-basis: calc(500px + 10vw);
  /* max-width: 40vw; */
  margin-top: 1rem;
  margin-right: 0.5rem;
  overflow: hidden;
  position: relative;
}

.player:hover {
  border: 5px solid var(--hl-blue);
  border-radius: 5px;
}

.player__video {
  width: calc(500px + 10vw);
}

.player__button {
  background: none;
  border: 0;
  line-height: 1;
  color: white;
  text-align: center;
  outline: 0;
  padding: 0;
  cursor: pointer;
  max-width: 50px;
}

.player__button:hover {
  background: var(--hl-yellow);
  border-radius: 5px;
}

.player__button:focus {
  border-color: var(--solid-green);
}

.player__slider {
  width: 10px;
  height: 30px;
}

.player__slider:hover {
  background: var(--hl-blue);
  border-radius: 5px;
}

.player__controls {
  display: flex;
  position: absolute;
  bottom: 0;
  width: 100%;
  transform: translateY(100%) translateY(-5px);
  transition: all 0.3s;
  flex-wrap: wrap;
  background: rgba(0, 0, 0, 0.1);
}

.player:hover .player__controls {
  transform: translateY(0);
}

.player:hover .progress {
  height: 15px;
}

.player__controls > * {
  flex: 1;
}

.progress {
  flex: 10;
  position: relative;
  display: flex;
  flex-basis: 100%;
  height: 5px;
  transition: height 0.3s;
  background: rgba(0, 0, 0, 0.5);
  cursor: ew-resize;
}

.progress:hover {
  background: var(--hl-orange);
  border-radius: 5px;
}

.progress:hover .progress__filled {
  background: var(--solid-blue);
}

.progress__filled {
  width: 50%;
  background: var(--solid-green);
  flex: 0;
  flex-basis: 25%;
}

/* unholy css to style input type="range" */
input[type='range'] {
  -webkit-appearance: none;
  background: transparent;
  width: 100%;
  margin: 0 5px;
}
input[type='range']:focus {
  outline: none;
}
input[type='range']::-webkit-slider-runnable-track {
  width: 100%;
  height: 8.4px;
  cursor: pointer;
  box-shadow: 1px 1px 1px rgba(0, 0, 0, 0), 0 0 1px rgba(13, 13, 13, 0);
  background: rgba(255, 255, 255, 0.8);
  border-radius: 1.3px;
  border: 0.2px solid rgba(1, 1, 1, 0);
}
input[type='range']::-webkit-slider-thumb {
  height: 15px;
  width: 15px;
  border-radius: 50px;
  background: var(--solid-green);
  cursor: pointer;
  -webkit-appearance: none;
  margin-top: -3.5px;
  box-shadow: 0 0 2px rgba(0, 0, 0, 0.2);
}
input[type='range']:focus::-webkit-slider-runnable-track {
  background: #bada55;
}
input[type='range']::-moz-range-track {
  width: 100%;
  height: 8.4px;
  cursor: pointer;
  box-shadow: 1px 1px 1px rgba(0, 0, 0, 0), 0 0 1px rgba(13, 13, 13, 0);
  background: #ffffff;
  border-radius: 1.3px;
  border: 0.2px solid rgba(1, 1, 1, 0);
}
input[type='range']::-moz-range-thumb {
  box-shadow: 0 0 0 rgba(0, 0, 0, 0), 0 0 0 rgba(13, 13, 13, 0);
  height: 15px;
  width: 15px;
  border-radius: 50px;
  background: var(--solid-green);
  cursor: pointer;
}

              
            
!

JS

              
                /* eslint-disable no-use-before-define */
/* eslint-disable no-underscore-dangle */
/* player elements */
const player = document.querySelector('.player')
const viewer = player.querySelector('.viewer')
const [playButton, ...skipButtons] = player.querySelectorAll('button')
const progressBar = player.querySelector('.progress')
const progress = player.querySelector('.progress__filled')
const volumeSlider = player.querySelector('[name="volume"]')
const playbackSlider = player.querySelector('[name="playbackRate"]')

/* inspector */
const inspector = {
  clearButton: document.querySelector('.inspector__button--clear'),
  currentFocus: null,
  currentFocusName: document.querySelector('.inspector__current-item'),
  inspectorMode: false,
  log: [],
  modeButton: document.querySelector('.inspector__button--inspector'),
  payloads: { initialized: false },
  target: document.querySelector('.inspector__window'),
  wrapper: document.querySelector('.inspector'),
  _mount() {
    this.clearButton.addEventListener('click', this.clearFocus.bind(this))
    this.modeButton.addEventListener('click', this.toggleInspectorMode.bind(this))
    this.setFocus('')
    this._render()
  },
  _render() {
    this.wrapper.style.height = `${player.offsetHeight}px`
  },
  clearFocus() {
    this.target.innerHTML = ''
    this.setFocus(null)
  },
  colorize(string, payload = null) {
    if (!payload) return string
    const colorized = string.replace(
      payload.regex,
      `<span style="color: ${payload.color};">${payload.name}</span>`,
    )
    return colorized
  },
  expose(string, payload = null) {
    if (!this.inspectorMode) {
      this.target.innerHTML = ''
      this.log.push({ name: payload.name, string: this.colorize(string, payload) })
      this.refresh()
    }
  },
  refresh() {
    this.target.innerHTML = ''
    this.log.forEach((line, index) => {
      if (line.string.includes(this.currentFocus)) {
        this.target.innerHTML += `<span style="display:inline-block;background:var(--solid-gray);font-size:1.5rem;padding:.25rem .5rem;text-align:right;width:3.25rem;">${index}</span> ${
          line.string
        }<br>`
      }
    })
    this.target.scrollTop = this.target.scrollHeight - this.target.offsetHeight
  },
  setFocus(item) {
    this.currentFocus = item ? item.name : ''
    this.currentFocusName.innerHTML = item ? item.name : '[All]'
    this.refresh()
  },
  toggleInspectorMode() {
    this.modeButton.classList.toggle('off')
    this.inspectorMode = !this.inspectorMode
  },
}

/* assign handlers */
function handlePlayPause() {
  if (inspector.inspectorMode) {
    inspector.setFocus(PL_VIEWER)
    return
  }
  const method = viewer.paused ? 'play' : 'pause'
  viewer[method]()
  this.innerHTML = viewer.paused ? '►' : 'II'
  inspector.expose(`playButton.innerHTML = ${viewer.paused ? '►' : 'II'}`, PL_PLAY_BUTTON)
  inspector.expose(`viewer.${method}()`, PL_VIEWER)
}
function handleProgressChange() {
  progress.style.flexBasis = `${(viewer.currentTime / viewer.duration) * 100}%`
}
function handleSkip() {
  if (inspector.inspectorMode) return
  viewer.currentTime += parseFloat(this.dataset.skip)
  inspector.expose(`viewer.currentTime += ${this.dataset.skip}`, PL_VIEWER)
  inspector.expose(
    `progressBar.style.flexBasis = "${(viewer.currentTime / viewer.duration).toFixed(2) * 100}%"`,
    PL_PROGRESS,
  )
  handleProgressChange()
}
function handleScrub(e) {
  const percent = e.offsetX / this.offsetWidth
  progress.style.flexBasis = `${percent * 100}%`
  viewer.currentTime = parseFloat(percent) * viewer.duration
}

/* constants */
const PL_VIEWER = { name: 'viewer', regex: /viewer/gi, color: 'var(--solid-blue)' }
const PL_PLAY_BUTTON = { name: 'playButton', regex: /playButton/gi, color: 'var(--solid-orange)' }
const PL_PROGRESS = { name: 'progressBar', regex: /progressBar/gi, color: 'var(--solid-green)' }
const PL_VOLUME = { name: 'volumeSlider', regex: /volumeSlider/gi, color: 'var(--solid-goldenrod)' }
const PL_PLAYBACK = {
  name: 'playbackRateSlider',
  regex: /playbackRateSlider/gi,
  color: 'var(--solid-pink)',
}

/* state variables */
let canScrub = false

/* listeners */
/* buttons */
viewer.addEventListener('click', handlePlayPause.bind(playButton))
playButton.addEventListener('click', handlePlayPause)
skipButtons.forEach((button) => {
  button.addEventListener('click', handleSkip)
})

/* sliders */
playbackSlider.addEventListener('input', (e) => {
  viewer.playbackRate = e.target.value
  inspector.expose(`playbackRateSlider.value = ${e.target.value}`, PL_PLAYBACK)
  inspector.expose(`viewer.playbackRate = ${viewer.playbackRate}`, PL_VIEWER)
})
playbackSlider.addEventListener('click', () => {
  if (inspector.inspectorMode) inspector.setFocus(PL_PLAYBACK)
})
volumeSlider.addEventListener('input', (e) => {
  viewer.volume = e.target.value
  inspector.expose(`volumeSlider.value = ${e.target.value}`, PL_VOLUME)
  inspector.expose(`viewer.volume = ${viewer.volume}`, PL_VIEWER)
})
volumeSlider.addEventListener('click', () => {
  if (inspector.inspectorMode) inspector.setFocus(PL_VOLUME)
})

/* progress bar */
viewer.addEventListener('timeupdate', handleProgressChange)
progressBar.addEventListener('mousedown', () => {
  if (inspector.inspectorMode) inspector.setFocus(PL_PROGRESS)
  else {
    canScrub = true
  }
})
progressBar.addEventListener('mousemove', (e) => {
  if (canScrub) handleScrub.call(progressBar, e)
})
progressBar.addEventListener('mouseup', (e) => {
  if (canScrub) {
    handleScrub.call(progressBar, e)
    inspector.expose(`viewer.currentTime = ${viewer.currentTime.toFixed(2)}s`, PL_VIEWER)
    inspector.expose(
      `progressBar.style.flexBasis = "${(viewer.currentTime / viewer.duration).toFixed(2) * 100}%"`,
      PL_PROGRESS,
    )
    canScrub = false
  }
})

/* RENDER */
window.onload = () => {
  inspector._mount()
}
window.onresize = () => {
  inspector._render()
}

              
            
!
999px

Console