2012-03-18 64 views
0

如何阻止多个Youtube视频在Twitter上播放Bootstrap模型关闭?如何停止Twitter上的Youtube视频播放引导模型关闭

这是我...当我只有一个视频,它工作正常...

var player = document.getElementById('MjXAo2qxMlA'); //save the object or embed youtube video in a variable 
$('#ttvideoModalTwo').on('hide', function() { 
    player.stopVideo(); 
}) 

var player = document.getElementById('zXscUitXHPc'); //save the object or embed youtube video in a variable 
$('#ttvideoModalOne').on('hide', function() { 
    player.stopVideo(); 
}) 

回答

1

根据API,你可以通过$.stopVideo()功能从停止播放视频,包括您modal('hide')方法内,你应该能够停止视频一旦模式是封闭的,像这样:

JS

var player = document.getElementById('objectId'); //save the object or embed youtube video in a variable 
$('#myModal').on('hide', function() { 
    player.stopVideo(); 
}) 

Youtube API Documentation

+0

Ilich我正在使用data-dismiss =“modal”数据属性来关闭我的模态。当我使用您提供的代码时,它会打破我的模式关闭按钮,模态只会保持打开状态。有关如何解决这个问题的任何想法?谢谢! – 2012-04-28 04:57:02

+0

@MarkRummel你可以在http://jsfiddle.net上提供你的代码吗?我想看看你的标记。 – 2012-04-28 12:49:40

+0

我收到了同样的问题,我用相关的代码更新了我的问题。 – 2012-07-26 13:08:26

1

这是停止视频播放

<div class="modal fade" id="video_3" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" > 
    <button class="close" data-dismiss="modal" type="button">×</button> 
    <iframe id="ivideo_3" width="560" height="315" src="http://www.youtube.com/embed/9wiDMU-NnKU?wmode=transparent&enablejsapi=1&origin=http://<YOUR_SITE_HERE.com>" frameborder="0" ></iframe> 
</div> 

<script> 
    //Load player api asynchronously. 
    var tag = document.createElement('script'); 
    tag.src = "//www.youtube.com/iframe_api"; 
    var firstScriptTag = document.getElementsByTagName('script')[0]; 
    firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 
    var done = false; 
    var player_3; 
    function onYouTubeIframeAPIReady() { 
     player_3 = new YT.Player('ivideo_3'); 
     $('#video_3').on('hide', function() { 
      player_3.stopVideo(); 
     }); 
    } 
</script> 
相关问题