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

              
                <div class="container">
  <div class="slick">
    <div class="item youtube">
      <iframe id="youtube" width="920" height="518" src="https://www.youtube-nocookie.com/embed/ScMzIvxBSi4?rel=0&amp;enablejsapi=1" frameborder="0" allowfullscreen></iframe> <!-- Make sure to enable the API by appending the "&enablejsapi=1" parameter onto the URL. -->
      <p class="caption">YouTube</p>
    </div>
    <div class="item vimeo">
      <iframe id="vimeo" src="https://player.vimeo.com/video/100902001?byline=0&amp;portrait=0&amp;api=1" width="920" height="517" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <!-- Make sure to enable the API by appending the "&api=1" parameter onto the URL. -->
      <p class="caption">Vimeo</p>
    </div>
  </div>
</div>
              
            
!

CSS

              
                body {
  background: #222;
  padding: 20px;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  width: 90%;
}

.slick {
  background: #EFEFEF;
  padding: 20px;
  .slick-slide {
    outline: none !important;
    -webkit-backface-visibility: hidden !important;
    * {
      -webkit-backface-visibility: hidden !important;
    }
  }
}

.caption {
  text-align: center;
  padding: 10px 0 0 0;
  color: #000;
  margin: 0;
  font-size: 24px;
}

.slick-prev, .slick-next {
  position: absolute;
  top: 50%;
  margin-top: -10px;
}
.slick-next {
  left: 105%;
}
.slick-prev {
  right: 105%;
}

.slick-dots {
  text-align: center;
  margin: 10px 0 0 0;
  li {
    display: inline-block;
    vertical-align: top;
    margin: 0 8px;
  }
}
              
            
!

JS

              
                (function($) {
  jQuery(document).ready(function($) {
    
    /*
     * The below example uses Slick Carousel, however this can be
     * extended into any type of carousel, provided it lets you
     * bind events when the slide changes. This will only work
     * if all framed videos have the JS API parameters enabled.
     */
    
    //bind our event here, it gets the current slide and pauses the video before each slide changes.
    $(".slick").on("beforeChange", function(event, slick) {
      var currentSlide, slideType, player, command;
      
      //find the current slide element and decide which player API we need to use.
      currentSlide = $(slick.$slider).find(".slick-current");
      
      //determine which type of slide this, via a class on the slide container. This reads the second class, you could change this to get a data attribute or something similar if you don't want to use classes.
      slideType = currentSlide.attr("class").split(" ")[1];
      
      //get the iframe inside this slide.
      player = currentSlide.find("iframe").get(0);
      
      if (slideType == "vimeo") {
        command = {
          "method": "pause",
          "value": "true"
        };
      } else {
        command = {
          "event": "command",
          "func": "pauseVideo"
        };
      }
      
      //check if the player exists.
      if (player != undefined) {
        //post our command to the iframe.
        player.contentWindow.postMessage(JSON.stringify(command), "*");
      }
    });
    
    //start the slider
    $(".slick").slick({
      infinite: false,
      arrows: false,
      dots: true
    });
    
    //run the fitVids jQuery plugin to ensure the iframes stay within the item.
    $('.item').fitVids();
    
  });
})(jQuery);
              
            
!
999px

Console