YouTube API模式弹出窗口无法在点击时播放

时间:2016-01-08 23:52:15

标签: javascript html css youtube

我很难接受这个,但我在JS中也不强。我可以按要求打开所有内容,但我只是无法通过点击按钮播放视频。以下是我的代码

之前/头

  <script type="text/javascript" src="http://www.youtube.com/player_api"></script>
<script>
  var player;
   function onYouTubePlayerAPIReady() {player = new YT.Player('my-video');}
</script>

按钮和模态

<a href="#" id="playVideoBtn" data-ix="fade-in-and-out" class="w-inline-block play-wrapper" ><img width="45" height="45" src="images/play-button-big.png">

<iframe id="my-video" style="position: relative; height: 100%; width: 100%; border:0px;" src="https://www.youtube.com/embed/7LTwhhs8GCo?rel=0&amp;controls=0&amp;showinfo=0&amp;enablejsapi=1"></iframe>

js before / body

  <script type="text/javascript">

$(document).ready(function() {

   $('#playVideoBtn').click(function(e) {
      e.preventDefault();
      $('.modal-background.video').fadeIn();
      player.playVideo();
    });
    $('#close-video').click(function(e) {
      e.preventDefault();
      $('.modal-background.video').fadeOut();
      player.stopVideo();
    });
    $('.modal-background-link').click(function(e) {
      e.preventDefault();
      $('.modal-background.video').fadeOut();
      player.stopVideo();
    });
  });

我做错了什么?

0 个答案:

没有答案