使用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"));