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="wrapper">
    <div class="js-video">
        <video class="js-media" poster="https://1.bp.blogspot.com/-jJUO43k6ReU/T7ivfcr4fgI/AAAAAAAAQqU/8YdJwPwT4OE/s1600/transparent.png">
	          <source src="http://assets.ign.com/videos/zencoder/1920/9a8c39b7746fbb40cb7a5bc0077afeb6-6500000-1414004354-w.mp4" type="video/mp4" />
            <p>Your user agent does not support the HTML5 Video element.</p>
        </video>
        <i data-playPause class="playPause fa fa-play ui-icon"><span></span></i>
        <div class="ui">
          <div>
            <div data-progress class="progress">
              <div data-buffer class="progress-buffer"></div>
              <div data-time class="progress-time"></div>
            </div><!-- progress -->
          </div>
          <div>
            <span class="timeDisplay"><i data-currentTime>0:00</i> / <i data-duration>0:00</i></span>
          </div>
          <div>
            <i data-mute class="fa fa-volume-up ui-icon"></i>
          </div>
          <div>
            <div data-volume="100" class="volumeControl"><span class="ui-slider-handle"></span></div>
          </div>
        </div><!-- ui -->
        <i data-fullscreen class="fullscreen iconicfill-fullscreen" title="fullscreen"></i>
      

      
    </div><!-- js-video -->

</div><!-- wrapper -->
              
            
!

CSS

              
                @import "compass/css3";

@import url(//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css);
@import url(http://weloveiconfonts.com/api/?family=iconicfill);

[class*="iconicfill-"]:before {
  font-family: 'IconicFill', sans-serif;
}


/*********************
 * Background
 *********************/
html { 
  background: #F4D17E url(//eventsonhand.com/wp-content/uploads/2013/07/blurred-background-10-2000x1250.jpg) no-repeat center center fixed; 
  background-size: cover;
  height: 100%;
}

body {
    font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif; 
  font-weight: 300;
  line-height: 1.4;
  height: 100%;
  @include display-flex();
  @include align-items(center);
  @include justify-content(center);
  margin: 0;
  padding: 0;
}

/*********************
 * Wrapper
 *********************/
.wrapper {
}

.js-video {
  position: relative;
  max-width: 600px;
  margin: 0 auto;
  padding: 10px;
  background: rgba(#000,0.2);
  border-radius: 8px;
}

/*********************
 * Elements inside js-video
 *********************/
video {
  max-width: 100%;
  max-height: 70vh;
  background: url(https://www.davestrailerpage.co.uk/images/hungergamesmockingjay800.jpg) no-repeat;
  background-size: cover;
  background-position: center center;
}

.js-video button {
  @include appearance(none);
}

/*********************
 * UI
 *********************/
.playPause.ui-icon {
  position: absolute;
  top: 10px;
  left: 10px;
  right: 0;
  display: block;
  width: auto;
  bottom: 56px;
  
  &:before, &:after {
    position: absolute;
    top: 50%;
    left: 50%;
  }
  
  $width: 80px;
  &:after {
    content: '';
    width: $width;
    height: $width;
    margin: #{$width * -0.5} 0 0 #{$width * -0.5};
    background: rgba(#000, .8);
    border-radius: 10px;
  }
  &:before {
    font-size: 40px;
    line-height: $width;
    color: rgba(#F4D17E, 0.5);
    z-index: 2;
    top: 50%;
    left: 50%;
    margin: -40px 0 0 -14px;
  }
  &.fa-pause, &.fa-undo {
    &:before {
      margin-left: -17px;
    }
  }
  &.fa-pause {
    opacity: 0;
  }
}

.ui {
  padding: 10px 1vw;
  font-size: 0;
  @include display-flex();
  > div {
    &:nth-of-type(1), &:nth-of-type(4) {
      padding-top: 8px;
    }
    &:nth-of-type(1) {
      @include flex(30 30 1px);
      margin-right: 10px;
    }
    &:nth-of-type(2) {
      @include flex(1 0 60px);
      font-size: 12px;
      margin-right: 10px;
      text-align: center;
      line-height: 20px;
    }
    &:nth-of-type(3) {
      @include flex(0 0 20px);
      margin-right: 10px;
    }
    &:nth-of-type(4) {
      @include flex(0 0 60px);
    }
  }
}

.timeDisplay {
  i {
    font-style: normal;
  }
  white-space: nowrap;
}

.fullscreen {
  position: absolute;
  font-style: normal;
  left: 20px;
  bottom: 66px;
  display: block;
  width: 40px;
  height: 40px;
  text-align: center;
  cursor: pointer;
  @include transition(color 0.3s);
  &:before {
    font-size: 30px;
    line-height: 40px;
    color: rgba(#F4D17E, .2);
  }
  &:hover {
    &:before {
      color: rgba(#F4D17E, .5);
    }
  }
}

.ui-icon {
  font-size: 20px;
  vertical-align: middle;
  width: 20px;
  margin-right: 10px;
  cursor: pointer;
}

/*********************
 * Progress
 *********************/
.progress, .volumeControl {
  background: rgba(#000,.1);
  width: 100%;
  position: relative;
  height: 5px;
  cursor: pointer;
  overflow: hidden;
  border-radius: 2px;
  border: 0;
}

.progress > * {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
}

.progress-time {
  background-color: rgba(0,0,0,1);
}

.anim {
  @include transition(width 1000ms linear);
}

.progress-buffer {
  background-color: rgba(0,0,0, 0.3);
  @include transition(width 250ms linear);
}

.volumeControl {
  width: 90%;
  overflow: visible;
  position: relative;
  background: rgba(#000,.3);
  .ui-slider-handle {
    position: absolute;
    width: 9px;
    height: 9px;
    border: 0;
    top: -2px;
    background: transparent;
    &:after {
      content: '';
      position: absolute;
      width: 100%;
      height: 100%;
      left: -50%;
      background: rgba(#000, 1);
      border-radius: 4px;
    }
    &:focus {
      outline: none;
    }
  };
}

              
            
!

JS

              
                (function($){
  'use strict';
  
  /**
   * Constructor
   */
  var Video = function($element) {
    
    /**
     * Make the reference to the passed
     * in element globally accessible within
     * the Video constructor
     */
    this.$element = $element;
    
    /**
     * Kick off the application
     */
    this.init();
  };
  
  /* Alias prototype */ 
  var proto = Video.prototype;
  
  /**
   * Top level function
   */
  proto.init = function() {
    
    return this.setupHandlers()
               .createChildren()
               .enable();
  };
  
  /**
   * Used to bind 'this' for functions
   */
  proto.setupHandlers = function() {
    this.onPlayPauseHandler = this.playPause.bind(this);
    this.onMuteHandler = this.mute.bind(this);
    this.onTimeUpdateHandler = this.progress.bind(this);
    this.onSeekHandler = this.seek.bind(this);
    this.onFullscreenHandler = this.fullscreenMode.bind(this);
    this.onVolumeHandler = this.adjustVolume.bind(this);

   
    return this;
  };
  
  /**
   * Create jQuery selectors here
   */
  proto.createChildren = function() {
    this.$video = this.$element.find('.js-media');
    this.$media = this.$video[0];
    this.$playBtn = this.$element.find('[data-playPause]');
    this.$muteBtn = this.$element.find('[data-mute]');
    this.$volume = this.$element.find('[data-volume]');
    this.$timeBar = this.$element.find('[data-time]');
    this.$bufferBar = this.$element.find('[data-buffer]');
    this.$progress = this.$element.find('[data-progress]');
    this.$currentTime = this.$element.find('[data-currentTime]');
    this.$duration = this.$element.find('[data-duration]');
    this.$fullscreen = this.$element.find('[data-fullscreen]');
    
    return this;
  };
  
  /**
   * Event listeners and functions that need
   * to run on initialization 
   */
  proto.enable = function() {
    this.$playBtn.on('click', this.onPlayPauseHandler);
    this.$muteBtn.on('click', this.onMuteHandler);
    this.$video.on('timeupdate', this.onTimeUpdateHandler)
                .on('loadedmetadata', function() {
                      this.updateTimeDisplay(0, this.$media.duration);
                    }.bind(this))
                .on('ended', function() {
                      this.$playBtn.removeClass('fa-play fa-pause')
                                   .addClass('fa-undo');
                      this.updateTime(100);
                    }.bind(this))
                ;
    this.$progress.on('mousedown', this.onSeekHandler)
                  .on('mouseup', this.onSeekHandler);
    this.$fullscreen.on('click', this.onFullscreenHandler);
    this.$volume.on('volumeChange', this.onVolumeHandler);
    
    return this;
  };
  
  /**
   * Get New Location
   *
   * Uses offsets within the tracking bar
   * to find the position in seconds that the
   * corresponds to in seconds of the video.
   *
   * Returns an object that has the new position 
   * of the seek bar and the actual time time 
   * seconds
   */
  proto.getNewLocation = function(e) {
    var seekBarOffset = this.$progress.offset().left;
    var mouseOffset = e.pageX;
    var mousePosInBar = mouseOffset - seekBarOffset;
    var seekBarWidth = this.$progress.width();
    var duration = this.$media.duration;
    var dist = Math.floor((mousePosInBar / seekBarWidth) * 100);
    var actualSeconds = (dist / 100) * duration;
    var newLocation = (actualSeconds/duration) * 100;
    
    var info = {
      newTime: newLocation,
      actualTime: actualSeconds
    };;
    
    return info;
  };
  
  /**
   * Seek
   *
   * Called on mousedown and mouseup in the progress bar
   * to set the position of the progress bar and time in the
   * video.
   */
  proto.seek = function(e) {
    var info = this.getNewLocation(e);
    this.$media.currentTime = info.actualTime; // Set the time
    this.updateTime(info.newTime);
  };
  
  /**
   * Play
   *
   * Plays or pauses the video
   */
  proto.playPause = function() {
    if (this.$media.paused) {
      this.play();
    } else {
      this.pause();
    }
  };
  
  proto.play = function() {
    this.$media.play();
    this.$playBtn.removeClass('fa-play fa-undo')
    .addClass('fa-pause');
  };
  proto.pause = function() {
    this.$media.pause();
    this.$playBtn.removeClass('fa-pause fa-undo')
    .addClass('fa-play');
  };

  
  /**
   * Mute 
   *
   * Mutes the video
   */
  proto.mute = function() {
    if (this.$media.muted) {
      this.$media.muted = false;
    } else {
      this.$media.muted = true;
    }
    
    this.muteIconSwap();
  };
  
  proto.muteIconSwap = function() {
    if (this.$media.muted) {
      this.$muteBtn.removeClass('fa-volume-up')
                   .addClass('fa-volume-off');
    } else {
      this.$muteBtn.removeClass('fa-volume-off')
                   .addClass('fa-volume-up');
    }
  };
  
  /**
   * Volume 
   *
   * Volume of the video
   */
  proto.adjustVolume = function() {
    var toVolume = this.$volume.data('volume') / 100;
    this.$media.volume = toVolume; // from 0 - 1
    if(toVolume === 0) {
      this.$media.muted = true;
    } else {
      this.$media.muted = false;
    }
    this.muteIconSwap();
  }

  /**
   * Progress
   *
   * 
   */
  proto.progress = function() {
    var currentTime = Math.round(this.$media.currentTime);
    var duration = this.$media.duration;
    var locationPercent = (currentTime/duration) * 100;
    var buffered = this.$media.buffered.end(0);
    var bufferPercent = Math.floor((buffered/duration) * 100);

    this.updateTime(locationPercent);
    this.updateBuffer(bufferPercent);
    this.updateTimeDisplay(Math.floor(this.$media.currentTime), duration);

  };
  
  /**
   * Update Buffer
   *
   * Updates the width of the buffer bar.
   */
  proto.updateBuffer = function(percent) {
    this.$bufferBar.css('width', percent + '%');
  };
  
  /**
   * Update Time
   *
   * Updates the width of the seek bar.
   */
  proto.updateTime = function(percent) {
    this.$timeBar.css('width', percent + '%');
  };

  proto.updateTimeDisplay = function(currentTime, duration) {
    this.$currentTime.text(formatTime(currentTime));
    this.$duration.text(formatTime(duration));
  }
  
  function formatTime(s, m) {
      s = Math.floor( s );    
      m = Math.floor( s / 60 );
      m = m >= 10 ? m : '0' + m;    
      s = Math.floor( s % 60 );
      s = s >= 10 ? s : '0' + s;    
      return m + ':' + s;
  }
  
   /**
   * Full screen
   *
   * Display video in fullscreen mode
   */
  proto.fullscreenMode = function() {
    var elem = this.$media;
    if (elem.requestFullscreen) {
      elem.requestFullscreen();
    } else if (elem.mozRequestFullScreen) {
      elem.mozRequestFullScreen();
    } else if (elem.webkitRequestFullscreen) {
      elem.webkitRequestFullscreen();
    }
  }
  
  /**
   * Update src 
   *
   * Update src of the video and reload
   */
  proto.updateSrc = function(newSource, poster) {
    var source = this.$video.find('source');
    $(source).attr('src', newSource);
    if(poster) {
      this.$video.attr('poster', poster);
    }
    this.$media.load();
  }
  
  
  // making it a jQuery plugin
  $.fn.video = function() {
    return this.each(function() {
      $(this).data('Video', new Video($(this)));
    });
  }


})(jQuery);

// embedabled movies https://www.davestrailerpage.co.uk/


// use jQuery UI slider for volume control
if($.fn.slider) {
  
  $('.volumeControl').slider({
    min: 0,
    max: 100,
    value: 100,
    slide: function( event, ui ) {
      $(this).data('volume', ui.value).trigger('volumeChange');
    }
  });
}

// Initialize the Video instance
$('.js-video').video();
  


              
            
!
999px

Console