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

              
                //- Container for the video player
.my-video-player
              
            
!

CSS

              
                *
  box-sizing border-box
  -webkit-tap-highlight-color transparent

body
  display flex
  align-items center
  justify-content center
  font-family 'HelveticaNeue-Light', 'Helvetica Neue Light', 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif
  min-height 100vh

.video-player
  --accent #19b5fe
  --border-width 5
  background var(--accent)
  overflow hidden
  position relative

  &__action
    position absolute
    font-weight bold
    font-size 2rem
    color #ffffff
    line-height 44px
    transform scale(0)
    background transparent
    border 0
    cursor pointer
    top 0
    right 0
    bottom 0
    left 0
    width 100%
    outline-color transparent
    outline 0

    svg
      height 2.5rem
      fill #ffffff

  &__indicator
    position absolute
    background var(--accent)

    &:nth-of-type(1)
    &:nth-of-type(3)
      height calc(var(--border-width) * 1px)
      width 100%
      transform-origin left
      transform scaleX(0)

    &:nth-of-type(2)
    &:nth-of-type(4)
      height 100%
      width calc(var(--border-width) * 1px)
      transform-origin bottom
      transform scaleY(0)

    &:nth-of-type(1)
      top 0

    &:nth-of-type(3)
      bottom 0

    &:nth-of-type(2)
      top 0
      right 0
      bottom 0

    &:nth-of-type(4)
      top 0
      left 0
      bottom 0

  video
    display block
    object-fit cover
    object-position center
    width 300px
    outline-color transparent

    @media(min-width 768px)
      width 640px

              
            
!

JS

              
                const { TimelineMax, TweenMax, Power0 } = window
const container = document.querySelector('.my-video-player')
/**
 *
 */
class VideoPlayer {
  indicators = []
  constructor(container, src) {
    this.container = container
    this.buildMarkup(src)
    this.bindStuff()
  }
  /**
   * Generate the markup for the video player based
   * on a video URL
   */
  buildMarkup = videoSrc => {
    this.video = document.createElement('video')
    this.video.src = videoSrc
    this.video.setAttribute('controls', true)
    this.video.classList.add('video-player__video')
    this.container.append(this.video)
    for (let i = 0; i < 4; i++) {
      const indicator = document.createElement('div')
      indicator.classList.add('video-player__indicator')
      this.indicators.push(indicator)
      this.container.append(indicator)
    }
    this.replay = document.createElement('button')
    this.replay.classList.add('video-player__action')
    this.replay.innerHTML = `
      <svg viewBox="0 0 24 24">
        <path d="M17.65,6.35C16.2,4.9 14.21,4 12,4A8,8 0 0,0 4,12A8,8 0 0,0 12,20C15.73,20 18.84,17.45 19.73,14H17.65C16.83,16.33 14.61,18 12,18A6,6 0 0,1 6,12A6,6 0 0,1 12,6C13.66,6 15.14,6.69 16.22,7.78L13,11H20V4L17.65,6.35Z" />
      </svg>
    `
    this.container.append(this.replay)
    this.container.classList.add('video-player')
  }
  buildTimelines = () => {
    const { indicators } = this
    this.timeline = new TimelineMax()
      .add(
        TweenMax.to(indicators[2], this.video.duration / 2, {
          scaleX: 1,
          ease: Power0.easeNone,
        }),
        0
      )
      .add(
        TweenMax.to(indicators[3], this.video.duration / 2, {
          scaleY: 1,
          ease: Power0.easeNone,
        }),
        0
      )
      .add(
        TweenMax.to(indicators[0], this.video.duration / 2, {
          scaleX: 1,
          ease: Power0.easeNone,
        }),
        this.video.duration / 2
      )
      .add(
        TweenMax.to(indicators[1], this.video.duration / 2, {
          scaleY: 1,
          ease: Power0.easeNone,
        }),
        this.video.duration / 2
      )

    this.timeline.seek(this.video.currentTime)
    this.timeline.paused(true)

    this.endTimeline = new TimelineMax({
      onComplete: () => this.timeline.seek(0),
      onReverseComplete: () => this.video.play(),
    })
      .add(
        TweenMax.to(this.video, 0.25, {
          scale: 0,
        })
      )
      .add(TweenMax.to(this.replay, 0.25, { scale: 1 }))
    this.endTimeline.paused(true)
  }
  play = () => {
    this.timeline.play()
  }
  pause = () => {
    if (this.timeline) {
      this.timeline.pause()
    }
  }

  end = () => {
    this.endTimeline.play()
  }

  seek = () => {
    if (this.timeline) {
      this.timeline.seek(this.video.currentTime)
    }
  }

  /**
   * Bind the different video events etc.
   */
  bindStuff = () => {
    this.video.addEventListener('play', this.play)
    this.video.addEventListener('pause', this.pause)
    this.video.addEventListener('ended', this.end)
    this.video.addEventListener('seeking', this.seek)
    this.video.addEventListener('durationchange', this.buildTimelines)
    this.replay.addEventListener('click', () => {
      this.video.currentTime = 0
      this.endTimeline.reverse()
    })
  }
}

new VideoPlayer(
  container,
  'https://s3-us-west-2.amazonaws.com/s.cdpn.io/605876/video-player-video.mp4'
)

              
            
!
999px

Console