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="container">
  <div class="row">
    <div class="col-xs-12 text-center">
      <h1>Bootstrap 3 Youtube Carousel</h1>
      <p>Replace the IDs of the carousel items with the IDs of the youtube videos you want to display</p>
    </div>
  </div>
  <div class="row">
    <div class="col-sm-8 col-sm-offset-2">
      <div id="random_number1" class="carousel slide youtube-carousel"  data-ride="carousel" data-interval="false">
        <div class="carousel-inner">
          <div class="video-container item active">
            <div class="youtube-video" id='AO89eXKO0c4'></div>
            <div class="carousel-caption">Video 1</div>
          </div>
          <div class="video-container item">
            <div class="youtube-video" id='6MjRVkm9CF0'></div>
            <div class="carousel-caption">Video 2</div>
          </div>
          <div class="video-container item ">
            <div class="youtube-video" id='R8poo-zCK9g'></div>
            <div class="carousel-caption">Video 3</div>
          </div>
        </div>
        <div class="controls">
          <a class="left carousel-control" href="#random_number1" data-slide="prev">
            <div class="left-button">
              <div class="glyphicon glyphicon-chevron-left"></div>
            </div>
          </a>
          <a class="right carousel-control" href="#random_number1" data-slide="next">        
            <div class="right-button">
              <div class="glyphicon glyphicon-chevron-right"></div>
            </div>
          </a>
        </div>
      </div>
    </div>
  </div>
</div>
              
            
!

CSS

              
                /*
 * Bootrap carousel plugin
 * --------------------------------------------------
 */

body{
  background-color: #e25454;
  color: #fff;
}

.youtube-carousel{
  border: 4px solid #e25454;
}

.video-container { 
   position: relative; /* keeps the aspect ratio */ 
   padding-bottom: 56.25%; /* fine tunes the video positioning */ 
   padding-top: 60px; overflow: hidden;
   margin-bottom: -1px;
   margin-right: -1px;   
}

.video-container iframe,
.video-container object,
.video-container embed {
  position: absolute;  
  top: 0; 
  left: 0; 
  width: 100%; 
  height: 100%;
}
  
.carousel-control .glyphicon-chevron-left{
  top:35%;
  font-size: 20px;
  left:5%;
  margin: 0;
}

.carousel-control .glyphicon-chevron-right{
  top:35%;
  font-size: 20px;
  left:33%;
  margin: 0;
}

.carousel-control.left, .carousel-control.right {
  background-image: none;
  color: #ffffff;
  top: 50%;
  transform: translate(0,-50%);
  -webkit-transform: translate(0,-50%);
  -ms-transform: translate(0,-50%);
  opacity: 1;
  height:120px;
}

.controls{
   display: none;
}

.carousel-control:hover {
  text-decoration: none;
  filter: alpha(opacity=60);
  outline: 0;
  opacity: 0.6;
}

.left-button {
  height:70px;
  width:35px;
  border-radius: 0 90px 90px 0;
  top: 50%;
  -webkit-transform: translate(0,-50%);
  -ms-transform: translate(0,-50%);
  transform: translate(0,-50%);
  -moz-border-radius: 0 90px 90px 0;
  -webkit-border-radius: 0 90px 90px 0;
  background-color: #e25454;
  display: inline-block;
  position: relative;
  float:left;
  /*subpixel bug*/
  margin-left: -1px; 
}

.right-button {
  height:70px;
  width:35px;
  border-radius: 90px 0 0 90px;
  top: 50%;
  -webkit-transform: translate(0,-50%);
  -ms-transform: translate(0,-50%);
  transform: translate(0,-50%);
  -moz-border-radius: 90px 0 0 90px;
  -webkit-border-radius: 90px 0 0 90px;
  background-color: #e25454;
  display: inline-block;
  position: relative;
  float:right;
  /*subpixel bug*/
  margin-right: -1px;
}


.carousel-caption {
 display: none;
 background: none repeat scroll 0 0 #e25454;
  bottom: 0;
  font-size: 12px;
  text-align: center;
  opacity: 1;
  padding:7px 30px 7px;
  text-transform: uppercase;
  z-index:11;
  pointer-events:none;
}

@media screen and (min-width: 768px) {
.right-button {
  height:120px;
  width:60px;
  border-radius: 90px 0 0 90px;
  -moz-border-radius: 90px 0 0 90px;
  -webkit-border-radius: 90px 0 0 90px;
  display: inline-block;
  position: relative;
  float:right;
}

.left-button {
  height:120px;
  width:60px;
  border-radius: 0 90px 90px 0;
  -moz-border-radius: 0 90px 90px 0;
  -webkit-border-radius: 0 90px 90px 0;
  display: inline-block;
  position: relative;
  float:left;
}

.carousel-control .glyphicon-chevron-left{
  top:35%;
  font-size: 35px;
  left:5%;
}

.carousel-control .glyphicon-chevron-right{
  top:35%;
  font-size: 35px;
  left:35%;
}

.carousel-caption {
  font-size: 18px;
  padding:15px 20px 15px;
  }
}
@media screen and (min-width: 992px) {
 .carousel-caption {
    font-size: 18px;
    padding:15px 20px 15px;
  }
}




              
            
!

JS

              
                //Start Youtube API
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

var youtubeReady = false;

//Variable for the dynamically created youtube players
var players= new Array();
var isPlaying = false;
function onYouTubeIframeAPIReady(){
  //The id of the iframe and is the same as the videoId	
  jQuery(".youtube-video").each(function(i, obj)  {
     players[obj.id] = new YT.Player(obj.id, {         
			  videoId: obj.id,
			    playerVars: {
			    controls: 2,
		      rel:0,
		      autohide:1,
		      showinfo: 0 ,
		      modestbranding: 1,
		      wmode: "transparent",
		      html5: 1
       	},    
        events: {
          'onStateChange': onPlayerStateChange
        }
       });
     });
     youtubeReady = true;
  }


function onPlayerStateChange(event) {
  var target_control =  jQuery(event.target.getIframe()).parent().parent().parent().find(".controls");
  
  var target_caption = jQuery(event.target.getIframe()).parent().find(".carousel-caption");
  switch(event.data){
    case -1:
      jQuery(target_control).fadeIn(500);
      jQuery(target_control).children().unbind('click');
      break
     case 0:
      jQuery(target_control).fadeIn(500);
      jQuery(target_control).children().unbind('click');
      break;
     case 1:
      jQuery(target_control).children().click(function () {return false;});
      jQuery(target_caption).fadeOut(500);
      jQuery(target_control).fadeOut(500);
       break;
      case 2:
        jQuery(target_control).fadeIn(500);
        jQuery(target_control).children().unbind('click'); 
        break;
        case 3:
           jQuery(target_control).children().click(function () {return false;});
           jQuery(target_caption).fadeOut(500);
           jQuery(target_control).fadeOut(500);
           break;
          case 5:
            jQuery(target_control).children().click(function () {return false;});
            jQuery(target_caption).fadeOut(500);
            jQuery(target_control).fadeOut(500);
            break;
          default:
            break;
    }
};

jQuery(window).bind('load', function(){
  jQuery(".carousel-caption").fadeIn(500);
  jQuery(".controls").fadeIn(500);
 });

jQuery('.carousel').bind('slid.bs.carousel', function (event) {
   jQuery(".controls").fadeIn(500);
});
              
            
!
999px

Console