【发布时间】: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');
}
});
});
谁能解释一下如何进行?
【问题讨论】:
-
您涉及到一些元素,因此请将 HTML 和 jQuery 一起发布到 MCVE (Minimal, Complete, and Verifiable Example)。
标签: javascript jquery video iframe youtube