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

              
                <div class="video-hero">
	
	<h1>Expanding Video Hero<span>click play to start</span></h1>
	
	<a href="#0" class="play"><span>Click to play video</span></a>
	
	<div class="overlay"></div>
	
	<img class="vid-cap" src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/15309/vid-cap.jpg" alt="Man biking in woods">
	
	<iframe src="https://player.vimeo.com/video/112233728?api=1&title=0&amp;byline=0&amp;portrait=0&amp;color=57c0d4" width="1060" height="596" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen class="video" aria-hidden="true" tabindex="-1"></iframe>
	
</div>

<div class="sub-hero">
	<h2>Heading Here</h2>
	<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Minima esse dicta, soluta nisi asperiores et perspiciatis, quos nesciunt officiis <a href="#">quod consectetur</a> repellendus magni cupiditate accusamus dolorum blanditiis, maiores expedita. Id.</p>
</div>
              
            
!

CSS

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

$babyBear: 320px;
$toddlerBear: 600px;
$mamaBear: 768px;
$papaBear: 993px;
$grandpaBear: 1200px;

html, body {
  height: 100%;
}

body {
  max-width: 1060px;
  margin: 0 auto;
  font-family: 'Rokkitt', serif;
  font-size: 120%;
}

.video-hero {
  
  max-height: 178px;
  position: relative;
  overflow: hidden;
  transition: all 1s ease-in-out;
  background: #000;
  
  @media(min-width: $toddlerBear){
    max-height: 300px;
  }
  
  @media(min-width: $mamaBear){
    max-height: 380px;
  }
  
  h1, .play, .overlay, .video {
    position: absolute;
  }
  
  h1 {
    top: 10px;
    text-align: center;
    z-index: 155;
    width: 100%;
    color: #fff;
    font-size: 25px;
    span {
      display: block;
      font-size: 80%;
      font-weight: 200;
    }
    @media(min-width: $toddlerBear){
      top: 20px;
      font-size: 60px;
    }
    @media(min-width: $mamaBear){
      top: 40px;
    }
  }
  
  .play {
    bottom: 10%;
    left: 50%;
    margin-left: -35px;
    z-index: 200;
    color: #fff;
    text-decoration: none;
    background: url("https://s3-us-west-2.amazonaws.com/s.cdpn.io/15309/play-circle.svg");
    width: 70px;
    height: 70px;
    background-size: 100%;
    span {
      display: inline-block;
      text-indent: -999em;
    }
    &:hover {
      opacity: .8;
    }
    @media(min-width: $toddlerBear){
      bottom: 12%;
    }
    @media(min-width: $mamaBear){
      bottom: 20%;
    }
  }
  
  .vid-cap { 
    width: 100%; 
    height: auto; 
    z-index: 100;
    position: relative;
  }
  
  .overlay {
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,.5);
    z-index: 150;
  }
  
  .video {
    top: 0;
    left: 0;
    z-index: 50;
  }
  
}

.sub-hero {
  padding: 0 1em;
  margin-bottom: 100px;
  h2 { font-size: 30px; }
}
              
            
!

JS

              
                $(function(){

	var $parent = $('.video-hero'),
			$video = $parent.find('iframe'),
			$playButton = $(".play"),
			$itemsToFadeOut = $(".vid-cap,.overlay,h1"),
			f = $video[0],
			url = $video.attr('src').split('?')[0],
			activeVideoClass = "video-started";

			// setup fitVids
			$parent.fitVids();

			// handle play click
			$playButton.click(function(e){
				
				e.preventDefault();
				
				// grab height of video
				var videoHeight = $video.height();
				
				// add class to hero when video is triggered
				$parent.addClass(activeVideoClass);
				
				// fade out the play button
				$(this).fadeOut("fast");
				
				// fade out poster image, overlay, and heading
				$itemsToFadeOut.fadeOut();
				
				// toggle accessibility features
				$video.attr({
					"aria-hidden" : "false",
					"tabindex" : "0"
				});
				
				// set focus to video for accessibility control
				$video.focus();
				
				// set height of hero based on height of video
				$parent.css("max-height",videoHeight).height(videoHeight);
				
				// send play command to Vimeo api
				runCommand('play');
				
			});

			// send play to vimeo api
			var runCommand = function(cmd){
				var data = {method : cmd};
				f.contentWindow.postMessage(JSON.stringify(data), url);
			}
			
			// handle resize
			$(window).resize(function(){
				var videoHeight = $video.height();
				if($(".video-started").size() === 1){
					$parent.height(videoHeight);
				}
			});
		
});

              
            
!
999px

Console