2012-03-18 63 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> 
相關問題