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="main-movie">
  <!--#js-main-movieで<iframe>タグを生成します-->
  <div id="js-main-movie"></div>
  <div class="main-title-wrap"></div>
</div>
<button id="pause">一時停止</button>
<button id="play">再生</button>
              
            
!

CSS

              
                * {
  margin: 0;
  padding: 0;
}

.main-movie {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 56.25%;
  overflow: hidden;
}

iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border: none;
}

.main-title-wrap {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

.buttons {
  display: flex;
  justify-content: center;
  margin: 10px auto 0;
  padding: 0;
  list-style: none;
}

.buttons > * {
  width: 240px;
  padding: 0 10px;
  box-sizing: border-box;
}

.buttons a {
  display: block;
  padding: 5px;
  background-color: #fff;
  border-radius: 6px;
  text-decoration: none;
  text-align: center;
}
              
            
!

JS

              
                //<script>タグを生成
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);


//iframeタグとプレイヤーを作成します
var player;
function onYouTubeIframeAPIReady() {
  player = new YT.Player('js-main-movie', { //js-main-movieはHTMLのid属性の値と同じ
    videoId: 'aqa9h-nL-TA',  //aqa9h-nL-TAはYouTubeの動画ID
    height: '360',
    width: '640',
    playerVars: {
      controls: 1,
      autoplay: 1,
      disablekb:1,
      enablejsapi: 1,
      iv_load_policy: 3,
      playsinline: 1,
      rel: 0,
      autohide:0,
    },
    events: {
      'onReady': onPlayerReady,
      'onStateChange': onPlayerStateChange
    }
  });
}


//YouTube APIは↓の関数を呼び出す
function onPlayerReady(event) {
  event.target.mute();
  event.target.playVideo();
}


//プレイヤーの状態が変化するとYouTube APIは↓の関数を呼び出します
//プレイヤーが終了するとまた動画の再生をします
function onPlayerStateChange(event) {
  var ytStatus = event.target.getPlayerState();
  if (ytStatus == YT.PlayerState.ENDED) {
    player.mute();
    player.playVideo();
  }
}


//動画の停止ボタン
const pause = document.getElementById("pause");
pause.addEventListener("click",function(){
  player.pauseVideo();
})


//動画の再生ボタン
const play = document.getElementById("play");
play.addEventListener("click",function(){
  player.playVideo();
})
              
            
!
999px

Console