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 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

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="top-movie-box">
  <div id="cover" class="movie-cover">
    <div id="movie"></div>
  </div>
</div>
<script>
  
  /*動画のアスペクト比が16:9以外の時はmovie_reSizeの第二引数で指定してください。*/
  movie_reSize('cover');
  window.onload = function(){
    movie_reSize('cover');
  };
  window.onresize = function(){
    movie_reSize('cover');
  }
  /*
  * target  → (string) 合わせる要素のIDを指定
  * size     → (string)動画の比率を指定、初期値'16:9'
  */
  function movie_reSize(target,size){
    if(typeof size === 'undefined'){
      size = '16:9';
    }
    sizeArray = size.split(':');
    sizeArray[0] = Number(sizeArray[0]);
    sizeArray[1] = Number(sizeArray[1]);
    if(!target ||  sizeArray[0] == 'NaN' || sizeArray[1] == 'NaN'){
      console.log('値が正しくありません。');
      return false;
    }else{
    var $cover = document.getElementById(target),
        $movieContent = document.getElementById('movie'),
        coverWidth = $cover.getBoundingClientRect().width,
        coverHeight = $cover.getBoundingClientRect().height,
        tatehi = coverHeight / sizeArray[1],
        yokohi = coverWidth / sizeArray[0],ansWidth,ansHeight;
    
    if(tatehi>yokohi){
      ansHeight = coverHeight;
      ansWidth = tatehi * sizeArray[0];
    }else{
      ansWidth = coverWidth;
      ansHeight = yokohi * sizeArray[1];
    }
    
    
    $movieContent.style.width = ansWidth+'px';
    $movieContent.style.height = ansHeight+160+'px';//160は投稿者情報などを消すために着けています。表示させたい場合は+160を消去してください。
    }
  }
</script>
<script>
  var tag = document.createElement('script');
  tag.src = "//www.youtube.com/iframe_api";
  var firstScriptTag = document.getElementsByTagName('script')[0];
  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
  var player;
  function onYouTubeIframeAPIReady() {
    var movieId = 'ApToyQwHLhk';//youtubeの動画のID。再生したい動画のIDを入力。
    player = new YT.Player('movie', {
      /*
      playerVarsで細かい設定ができます。
      コメントはどんな設定をしているか書いているだけです。
      */
      playerVars:{
        playsinline: 1,
        autoplay: 1, // 自動再生
        loop: 1, // ループ有効
        listType: 'playlist', //リスト再生(ループ再生に必要)
        playlist: movieId, // 再生する動画リスト(ループ再生に必要)
        controls: 0, // コントロールバー非表示
        enablejsapi: 1, //JavaScript API 有効
        modestbranding:1,//yutubeロゴの非表示
        iv_load_policy: 3, //動画アノテーションを表示しない
        disablekb:1, //キーボード操作OFF
        showinfo:0, //動画の再生が始まる前に動画のタイトルなどの情報を表示しない
        rel:0, //再生終了時に関連動画を表示しない
      },
      videoId:  movieId,
      events: {
        'onReady': onPlayerReady,//動画の準備ができたらonPlayerReadyを実行
        'onStateChange': onPlayerStateChange,
      }
    });
  }
  function onPlayerReady(e) {
    e.target.mute();//音声ミュート
    e.target.playVideo();//動画スタート(SP用)
  }
  function onPlayerStateChange(e){
    if(e.data == 1){
      document.getElementById('cover').style.opacity = 1;//動画の再生が始まったら表示
    }
  }
  
</script>

              
            
!

CSS

              
                html,body{
  height:100%;
}
body{
  .top-movie-box{
    height: 100%;
    position: relative;
    z-index: 0;
    overflow: hidden;
    .movie-cover{
      height: 100%;
      width: 100%;
      position: absolute;
      top: 0;
      left: 0;
      opacity: 0;
      transition: opacity 0.5s;
      &:before{
        content: '';
        display: block;
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 1;
      }
      #movie{
        width: 100%;
        height: 100%;
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%,-50%);
        z-index: -1;
        
      }
    }
  }
}
              
            
!

JS

              
                
              
            
!
999px

Console