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 CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

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'>
<iframe width="853" height="480" src="//www.youtube.com/embed/_0WPQ6oP1aY" frameborder="0" allowfullscreen></iframe>
</div>
            
          
!
            
              /*
* ModernTube Jquery plugin v1.1
* re-size youtube videos to container width this make youtube video responsive 
* Author: Mohamed Abo El-Ghranek 
* Author URL: facebook.com/midoghranek
* https://codepen.io/midoghranek/pen/wolxD
*/

(function($) {
  
  $.fn.moderntube = function(tube) {
    
    return this.each(function() {
      
      // select container tag 
      var container = $(this);
      
      // select iframe tag
       var video = container.find('iframe[src*="youtube.com"]'); 
      
      // empty height and width attributes before get new values      
      video.attr('height','').attr('width','');
      
      // get video container width 
      var videoWidth = $(this).width();
      
      // get video height
      var videoHeight = videoWidth * 480/853;
      
      // add new values for height and width
      video.attr('height',videoHeight).attr('width','100%');
      
      // Window resize to make it responsive and make sure that the video loaded
      $(window).bind('resize load', function() {
        var videoWidth = container.width();
        var videoHeight = videoWidth * 480/853;
        video.attr('height',videoHeight).attr('width','100%');
      });

    });   
    
  };
  
})(jQuery);

// Select div and give it width using css 
$('#container').moderntube();
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console