显示:没有不工作的iPhone模拟器



我目前正在将youtube视频嵌入网站。

我创建了自己的自定义播放和暂停按钮,其中一个在给定的时间显示。如果正在播放视频,则会显示暂停按钮;如果暂停视频,则显示播放按钮。

然而,在iOS模拟器上测试时,两个按钮都显示出来,display:none似乎不起作用。

以前有人见过这个吗?解决方案是什么?这看起来很奇怪。此外,当我在chrome中进行测试并检查它在iPhone上的外观时,它可以按预期工作,但模拟器显示出不同的行为。

请参阅下面的代码。奇怪的是,当你运行代码片段时,下面的代码中显示了同样的错误,然而,正如我之前在chrome上测试时提到的,它运行得很好。

<style>
  
#pause-button {
  display: none;
}
</style>
<script type="text/javascript">
  // global variable for the player
  var player;
  // this function gets called when API is ready to use
  function onYouTubePlayerAPIReady() {
    // create the global player from the video iframe
    player = new YT.Player('video', {
      events: {
        // call this function when player is ready to use
        'onReady': onPlayerReady,
        // call this function when player changes state i.e. when video ends
        'onStateChange': onPlayerStateChange
      }
    });
  }
  function onPlayerReady(event) {
    var playButton = document.getElementById("play-button");
    playButton.addEventListener("click", function() {
      player.playVideo();
      playButton.style.display = "none";
      pauseButton.style.display = "block";
    });
    var pauseButton = document.getElementById("pause-button");
    pauseButton.addEventListener("click", function() {
      player.pauseVideo();
      playButton.style.display = "block";
      pauseButton.style.display = "none";
    });
  }
  function onPlayerStateChange(event) {
    //replay when video ends      
    if (event.data === 0) {
      player.playVideo();
    }
  }
  // Inject YouTube API script
  var tag = document.createElement('script');
  tag.src = "https://www.youtube.com/player_api";
  var firstScriptTag = document.getElementsByTagName('script')[0];
  firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
</script>
<!-- Make sure ?enablejsapi=1 is on URL -->
<!-- &controls=0 hides controls -->
<!-- &showinfo=0 hides information -->
<!-- &rel=0 prevents related video been shown at the end -->
<iframe id="video" width="560" height="315" src="https://www.youtube.com/embed/YXsGr21GD0M?enablejsapi=1&html5=1&controls=0&showinfo=0&rel=0" frameborder="0" allowfullscreen></iframe>
<div class="buttons">
  <!-- if we needed to change height/width we could use viewBox here -->
  <svg class="button" id="play-button">
    <use xlink:href="#play-icon">
      <path id="pause-icon" data-state="playing" d="M11,10 L17,10 17,26 11,26 M20,10 L26,10 26,26 20,26" />
      </use>
  </svg>
  <svg class="button" id="pause-button">
    <use xlink:href="#pause-icon">
      <path id="play-icon" data-state="paused" d="M11,10 L18,13.74 18,22.28 11,26 M18,13.74 L26,18 26,18 18,22.28" />
      </use>
  </svg>
</div>

<use>标记呈现它们所指向的内容,而不应该呈现它们的子对象。

<use>标记的href(SVG2)或(xlink:href(SVG 1.1)属性应该通过路径的id指向您的路径。

在您的情况下,您可能会完全删除标签,只保留可以显示或隐藏的路径。

最新更新