YouTube JS 代码 - 100% 宽度,静音和锁定

YouTube JS code - 100% width, muted and locked

我有 JS 代码,必须将其转换为 100% width800px heightpointer-events: none; 是否有机会将其添加到此代码中? 此代码将 youtube 视频更改为静音。

<!-- 1. The <div> tag will contain the <iframe> (and video player) -->  
<div id="player"></div>
<script>      // 2. This code loads the IFrame Player API code asynchronously.
      var tag = document.createElement('script');
      tag.src = "http://www.youtube.com/player_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      // 3. This function creates an <iframe> (and YouTube player)
      //    after the API code downloads.
      var player;
      function onYouTubePlayerAPIReady() {
        player = new YT.Player('player', {
          playerVars: { 'autoplay': 1, 'controls': 0,'loop': 1,'playlist': '2oqCAmfc0D0','autohide':1,'showinfo': 0,'disablekb': 1,'rel': 0,'wmode':'opaque' },
          videoId: '2oqCAmfc0D0',
width: '100%',
          events: {
            'onReady': onPlayerReady}
        });
      }

      // 4. The API will call this function when the video player is ready.
      function onPlayerReady(event) {
        event.target.mute();
      }
</script>

你的意思是这样的? JSFiddle Example

<!-- 1. The <div> tag will contain the <iframe> (and video player) -->  
<div id="player" style="pointer-events: none;"></div>
<script>      // 2. This code loads the IFrame Player API code asynchronously.
      var tag = document.createElement('script');
      tag.src = "http://www.youtube.com/player_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

      // 3. This function creates an <iframe> (and YouTube player)
      //    after the API code downloads.
      var player;
      function onYouTubePlayerAPIReady() {
        player = new YT.Player('player', {
          playerVars: { 'autoplay': 1, 'controls': 0,'loop': 1,'playlist': '2oqCAmfc0D0','autohide':1,'showinfo': 0,'disablekb': 1,'rel': 0,'wmode':'opaque' },
          videoId: '2oqCAmfc0D0',
width: '100%',
height: '800px',
          events: {
            'onReady': onPlayerReady}
        });
      }

      // 4. The API will call this function when the video player is ready.
      function onPlayerReady(event) {
        event.target.mute();
      }
</script>

请注意,pointer-events 与旧版 IE 存在一些兼容性问题。参见 caniuse

做同样事情的另一种方法是覆盖div可见性:隐藏。或者叠加透明 div.