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>
  <div class="video-wrap">
    <video width="360" height="240" autoplay></video>
    <p>
      <button class="load-video">Load Video</button>
      <button class="play-video">Play</button>
      <button class="pause-video">Pause</button>
      <button class="seek-video">Seek +20s </button>
    </p>
  </div>
  <div class="console">
    Ready State: <span class="js-value"></span>
    <div class="events">
      <p>History State Change:</p>
      <div class="inner js-states"></div>
    </div>
  </div>
   <div class="console2">
    <div class="events">
      <p>History Events:</p>
      <div class="inner js-events"></div>
    </div>
  </div>
</div>  
              
            
!

CSS

              
                .video-wrap {
  float: left;
}
video {
  background: #000;
}
.console {
  float:left;
  margin-left: 20px;
  color: #fff;
  font-size: 12px;
  padding: 20px;
  width: 200px;
  height: 200px;
  background-color: green;
}

.console2 {
  float:left;
  margin-left: 20px;
  color: #fff;
  font-size: 12px;
  padding: 20px;
  width: 200px;
  height: 200px;
  background-color: red;
}

.inner {
  height: 150px;
  overflow:auto;
  font-size: 11px;
  color: #ddd;
}

.inner p {
  line-height: 14px;
  padding:0;
  margin: 0;
}
              
            
!

JS

              
                var videoSource = 'https://img-1252472236.cos.ap-beijing.myqcloud.com/%E3%80%904K%E3%80%91_72%20Seasons_%20of%20Makoto%20Shinkai%20%20%E6%96%B0%E6%B5%B7%E8%AA%A0%20%E3%80%8C%E4%BA%8C%E5%8D%81%E5%9B%9B%E7%AF%80%E6%B0%97%20%C2%B7%20%E4%B8%83%E5%8D%81%E4%BA%8C%E5%80%99%E3%80%8D.mp4';

var STATE = [
  'HAVE_NOTHING',
  'HAVE_METADATA',
  'HAVE_CURRENT_DATA',
  'HAVE_FUTURE_DATA',
  'HAVE_ENOUGH_DATA'
];

var loadStartTime = 0;

var appendStateChange = function (type, name) {
  var innerEl = document.querySelector('.js-states');
  var p = document.createElement('p');
  var str = ''
  if (type === 'action') {
    loadStartTime = Date.now();
    str = loadStartTime + ':' + name
  } else {
    str = '+' + (Date.now() - loadStartTime) + 'ms:' + name
  }
  if (!loadStartTime) {
    return;
  }
  p.innerText = str;
  innerEl.appendChild(p);
}

var currentState;
var videoEl = document.querySelector('video');
var readyStateInterval = function() {
  var valElm = document.querySelector('.js-value');
  if (currentState !== videoEl.readyState) {
    currentState = videoEl.readyState;
    appendStateChange('state', STATE[videoEl.readyState]);
    appendStateChange('state', 'paused: ' + videoEl.paused);
  }
  valElm.innerText = STATE[videoEl.readyState];
}

const events = [
  'loadedmetadata',
  'loadeddata',
  'canplay',
  'canplaythrough',
]

events.forEach(function(item) {
  videoEl.addEventListener(item, function() {
    var innerEl = document.querySelector('.js-events');
    var p = document.createElement('p');
    var str = ''
    str = '+' + (Date.now() - loadStartTime) + 'ms:' + item;
     p.innerText = str;
    innerEl.appendChild(p);
  });
})






window.onload = function() {
  setInterval(readyStateInterval, 15);
  
  var loadbtn = document.querySelector('.load-video');
  loadbtn.onclick = function() {
    videoEl.src = videoSource;
    videoEl.load();
    appendStateChange('action', 'load');
  }
  
  var playBtn = document.querySelector('.play-video');
  playBtn.onclick = function() {
    videoEl.play()
    appendStateChange('action', 'play');
  }
  
  var pauseBtn = document.querySelector('.pause-video');
  pauseBtn.onclick = function() {
    videoEl.pause()
    appendStateChange('action', 'pause');
  }
  
  var seekBtn = document.querySelector('.seek-video');
  seekBtn.onclick = function() {
    videoEl.currentTime += 20
    appendStateChange('action', 'seek');
  }
}
              
            
!
999px

Console