【问题标题】:How to get Youtube video in jQuery?如何在 jQuery 中获取 Youtube 视频?
【发布时间】:2016-12-13 14:15:13
【问题描述】:

我的 iframe 中有这个嵌入视频

<iframe id="Frustrated" width="560" height="315"src="https://www.youtube.com/embed/mjQwedC1WzI" frameborder="0" allowfullscreen sandbox="allow-scripts allow-same-origin"></iframe>

使用普通视频,您会得到类似的东西

$('#Frustrated').get(0)

获取视频并使用它调用函数。

但是,当我尝试对 YouTube 视频执行此操作时,它不起作用。我在 Google 开发页面上读到应该设置 API 并遵循它。但是,我从未使用过 API,我发现这整个事情非常混乱。

这是我目前拥有的 jQuery,我正在尝试在 iframe 上进行工作。

jQuery(document).ready(function($) {
    var video = $('section iframe').get(0);

    video.onended = function(e) {
      $('section iframe').animate({ width: "50%"}, 'slow', function(){
          $('#information').fadeIn('slow');
      });
    }

    video.onplay = function(e) {
        $('#information').fadeOut('slow', function(){
    $('section iframe').animate({ width: "100%" }, 'slow');
    });
    }

    $('section iframe').click(function() {

        if(this.paused || this.ended){
            $('#information').fadeOut('slow', function(){
           $('section iframe').animate({ width: "100%" }, 'slow', function(){
           video.play();
           });
            });
        } 

        else if (this.play) {
          video.pause();
          $('section iframe').animate({ width: "50%" }, 'slow');
              $('#information').fadeIn('slow');
    }
    });
});

谁能解释一下如何进行?

【问题讨论】:

标签: javascript jquery video iframe youtube


【解决方案1】:
猜你喜欢
  • 2013-04-04
  • 1970-01-01
  • 2015-08-09
  • 1970-01-01
  • 2015-03-06
  • 2013-02-06
  • 2023-03-17
  • 2023-03-11
  • 1970-01-01
相关资源
最近更新 更多