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

              
                <a href="https://youtu.be/lA4sqcZhPx4" target="_blank" data-keyframers-credit style="color: #000"></a>
<script src="https://codepen.io/shshaw/pen/QmZYMG.js"></script>
<div id="app">
  
  <header class="ui-header">
    <div class="ui-subheading">The best show you've ever seen</div>
    <h1 class="ui-heading">@keyframers</h1>
  </header>
  
  <div class="ui-arrow"></div>
  
  <nav class="ui-nav">
    <a href="#">Coding</a>
    <a href="#">Animating</a>
    <a href="#">Streaming</a>
    <a href="#">Punning</a>
  </nav>
  
  
  <div class="video-tile -first">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/39255/kf_glacier_1.jpg" />
    <video src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/39255/kf_glacier_1.mp4" preload="auto" loop="true"></video>
  </div>
  
  <div class="video-tile -second">
    <img src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/39255/kf_glacier_2.jpg" />
    <video src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/39255/kf_glacier_2.mp4" preload="auto" loop="true"></video>
  </div>
  
  <div class="video-toggle">
    <div class="video-toggle-inner">
      <video src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/39255/kf_glacier_3.mp4"></video>
    </div>
  </div>
</div>
              
            
!

CSS

              
                @import url("https://fonts.googleapis.com/css?family=Open+Sans:400,700");

$color-primary: #4066c8;

html {
  font-family: "Source Sans Pro", sans-serif;
}

html,
body {
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  background: #ddd;
}

* {
  position: relative;
  box-sizing: border-box;
}

body,
#app {
  &:before {
    content: "";
    display: block;
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    width: 35vw;
    background: $color-primary;
  }
}

body:before {
  background: darken($color-primary, 8%);
}
// ---------------------------
#app {
  background: #fff;
  width: 90vw;
  height: 70vh;
  overflow: hidden;
  box-shadow: 0 0.5rem 3rem rgba(black, 0.1);
  padding: 2rem 3rem;
  
  display: grid;
  grid-template-rows: 1fr 1fr 1fr;
  grid-template-columns: 1fr;

  // 3d environment
  transform-style: preserve-3d;
  perspective: 1000px;
}

.ui-header {
  grid-row: 1 / 2;
  align-self: end;
}

.ui-heading {
  margin: 0;
  font-weight: 300;
  font-size: 2.5rem;
}

.ui-subheading {
  text-transform: uppercase;
  font-size: .6rem;
  color: #aaa;
  font-weight: bold;
  letter-spacing: .5px;
  margin-bottom: .1rem;
}

.ui-heading,
.ui-subheading,
.ui-nav > a {
  animation: slide-left 2.5s cubic-bezier(0, 1, .2, 1) both,
    fade-in 0.6s linear both;
}

@for $i from 1 through 4 {
  .ui-nav > a:nth-child(#{4 - $i}) {
    animation-delay: .2s * $i, .2s * $i;
  }
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes slide-left {
  from { transform: translateX(-2rem); }
}

.ui-nav > a {
  text-decoration: none;
  color: #444;
  font-weight: 600;

  ~ a {
    opacity: 0.3;
  }
}

.video-tile,
.video-toggle {
  position: absolute;
}

.video-tile {
  // display: none;
  position: absolute;
  overflow: hidden;
  z-index: 1;
  transition: transform 0.4s linear;

  video {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    max-width: none;
    max-height: 100%;
    min-width: 100%;
    min-height: 100%;
    z-index: -1;
  }
}

.video-tile.-first {
  left: 30%;
  bottom: 10%;
  width: 50%;
  animation: video-tile-enter 2.5s cubic-bezier(0, 1, .2, 1) backwards;
}

.video-tile.-second {
  right: 5%;
  top: 10%;
  width: 30%;
  animation: video-tile-enter 3s cubic-bezier(0, 1, .1, 1) backwards;
}

@keyframes video-tile-enter {
  from {
    opacity: 0;
    pointer-events: none;
    transform: translateX(30%) rotateY(20deg);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.video-tile img {
  width: 100%;
  opacity: 1;
  transition: opacity 0.3s linear;
  display: block;
}

.video-tile:hover,
.video-tile:focus {
  z-index: 2;
  // transform: scale(1.1) !important;
  img {
    opacity: 0;
  }
}

.video-toggle {
  overflow: hidden;
  transform: translate(calc(50% - 5rem), calc(50% - 5rem));
  z-index: 9;
  visibility: hidden;
  cursor: pointer; 

  &,
  .video-toggle-inner {
    position: absolute;
    width: 100%;
    height: 100%;
    overflow: hidden;
    transition: transform 0.6s cubic-bezier(0.6, 0, 0.4, 1);
  }

  .video-toggle-inner {
    transform: translate(calc(-100% + 10rem), calc(-100% + 10rem));

    &:before {
      pointer-events: auto;
      content: "▶";
      height: 10rem;
      width: 10rem;
      border: solid 1px white;
      bottom: 0;
      right: 0;
      position: absolute;
      z-index: 1;
      display: flex;
      justify-content: center;
      align-items: center;
      font-size: 5rem;
      background-color: white;
      color: $color-primary;
      text-shadow: 0 0.25rem 1rem rgba(black, 0.1);
      transition: opacity 0.3s linear 0.3s;
      visibility: visible;
    }
  }

  video {
    transform: translate(calc(-50% + 15rem), calc(-50% + 10rem));
    position: absolute;
    top: 50%;
    left: 50%;
    min-width: 100%;
    min-height: 100%;
    max-width: initial;
    width: auto;
    transition: inherit;
    visibility: visible;
  }

  &.active {
    pointer-events: auto;

    &,
    .video-toggle-inner {
      transform: none;
    }

    .video-toggle-inner:before {
      opacity: 0; 
      transition-delay: 0s;
    }

    video {
      transform: translate(-50%, -50%);
    }
  }
}

video,
img {
  max-width: 100%;
  height: auto;
}

.ui-nav {
  grid-row: 3 / 4;
  display: flex;
  flex-direction: column;
  align-self: end;

  > * {
    line-height: 1.5;
  }
}

              
            
!

JS

              
                console.clear();

Array.from(
  document.querySelectorAll('.video-tile'),
  function(el){
    const video = el.querySelector('video');

    el.addEventListener('mouseenter', () => { 
      video.play()
    });

    el.addEventListener('mouseleave', () => {
      video.pause();
      setTimeout(() => { video.currentTime = 0 }, 400);
    });
  });

const elVideoToggle = document.querySelector('.video-toggle');

elVideoToggle.addEventListener('click', e => {
  elVideoToggle.classList.toggle('active');
  const condition = elVideoToggle.matches('.active');
  elVideoToggle.querySelector('video')[ condition ? 'play' : 'pause' ]();
});
              
            
!
999px

Console