使用javascript或jquery暂停YouTube视频 [英] Pause youtube video using javascript or jquery
本文介绍了使用javascript或jquery暂停YouTube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用jQuery或JavaScript来暂停YouTube视频
I need to pause the youtube video using jQuery or javascript
我在js中的代码
my code in js
var class_name = $('#videobuttonChange').attr('class').split(' ')[1];
if (class_name == "play") {
$("#vid_url").html('<iframe width="100%" height="270px" id="v_frame" src="http://www.youtube.com/v/uPiVOofEPHM?version=3&f=playlists&c=youtube_it&app=youtube_gdata&autoplay=1" frameborder="0" allowfullscreen wmode="Opaque"></iframe>');
} else {
$("#vid_url").html('<iframe width="100%" height="270px" id="v_frame" src="http://www.youtube.com/v/uPiVOofEPHM?version=3&f=playlists&c=youtube_it&app=youtube_gdata" frameborder="0" allowfullscreen wmode="Opaque"></iframe>');
}
在其他情况下,我需要暂停视频,但我的代码充当停止视频。如何暂停视频。
In else condition i need to pause the video but my code act as stopped the video. How to pause the video.
任何人都可以引导我。
推荐答案
在添加到DOM之前,您可以尝试有条件地配置 iframe
:
You could try conditionally configuring the iframe
before appending it to the DOM:
var video = $('<iframe></iframe>');
video.attr({'width': '100%',
'height': '270px',
'id': 'v_frame',
'src': 'http://www.youtube.com/v/uPiVOofEPHM?version=3&f=playlists&c=youtube_it&app=youtube_gdata',
'frameborder': '0',
'allowfullscreen': '',
'wmode': 'Opaque'});
if($('#videobuttonChange').hasClass('play')) {
video.attr('src', video.attr('src') + '&autoplay=1');
}
video.appendTo($("#vid_url"));
这篇关于使用javascript或jquery暂停YouTube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文