cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div id="container">
  <center>
    <p>Open the lightbox with below button</p>
    <button id="playme" onclick="revealVideo('video','youtube')">Play Video</button>
  </center>
</div>

<div id="video" class="lightbox" onclick="hideVideo('video','youtube')">
  <div class="lightbox-container">  
    <div class="lightbox-content">
      
      <button onclick="hideVideo('video','youtube')" class="lightbox-close">
        Close | ✕
      </button>
      <div class="video-container">
        <iframe id="youtube" width="960" height="540" src="https://www.youtube.com/embed/WsptdUFthWI?showinfo=0" frameborder="0" allowfullscreen></iframe>
      </div>      
      
    </div>
  </div>
</div>
            
          
!
            
              .lightbox {
  background-color: fade(black, 80%);  
  overflow: scroll;
  position: fixed;
  display: none;
  z-index: 1;
  bottom: 0;
  right: 0;
  left: 0;
  top: 0;
  
  &-container {
    position: relative;
    max-width: 960px;
    margin: 7% auto;
    display: block;    
    padding: 0 3%;
    height: auto;
    z-index: 10;
    
    // Increasing top margin for mobile
    @media screen and (max-width: 768px) { margin-top: 10%; }
    @media screen and (max-width: 414px) { margin-top: 13%; }
  }
    
  &-content {
    box-shadow: 0 1px 6px fade(black, 70%);
  }
  
  &-close {
    text-transform: uppercase;    
    background: transparent;
    position: absolute; 
    font-weight: 300;      
    font-size: 12px;
    display: block;
    border: none;
    color: white;
    top: -22px;
    right: 3%;
  }
}

.video-container {  
    padding-bottom: 56.25%;
    position: relative;  
    padding-top: 30px; 
    overflow: hidden;
    height: 0; 
}

.video-container iframe,
.video-container object,
.video-container embed {
    position: absolute;
    height: 100%;  
    width: 100%;  
    left: 0;  
    top: 0;
}

/* IGNORE FORM THIS POINT ON */

body {
  background: #efefef;
}

#container {
  border-radius: 4px;
  max-width: 300px;
  height: auto;
  padding: 50px;
  background: white;
  margin: 100px auto;
}

#playme {
  background: #007fed;
  text-transform: uppercase;
  font-weight: 300;
  border: none;
  color: white;
  padding: 10px 15px;
  display: inline-block;
  font-size: 14px;
  margin: 0;
}
            
          
!
            
              // Function to reveal lightbox and adding YouTube autoplay
function revealVideo(div,video_id) {
  var video = document.getElementById(video_id).src;
  document.getElementById(video_id).src = video+'&autoplay=1'; // adding autoplay to the URL
  document.getElementById(div).style.display = 'block';
}

// Hiding the lightbox and removing YouTube autoplay
function hideVideo(div,video_id) {
  var video = document.getElementById(video_id).src;
  var cleaned = video.replace('&autoplay=1',''); // removing autoplay form url
  document.getElementById(video_id).src = cleaned;
  document.getElementById(div).style.display = 'none';
}
            
          
!
999px
Loading ..................

Console