关闭模态时停止或静音FB视频

时间:2017-05-12 06:09:36

标签: javascript jquery twitter-bootstrap facebook

我有一个用于显示Facebook视频的引导模式弹出窗口,但是当我关闭它时,它会继续播放,我希望它在关闭模式时停止或至少静音。

我的代码:

<script>(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.9&appId=667393203349368";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>

    <div class="col-md-12" data-toggle="modal" data-target="#test-video-1">
    <a href="" onclick="return false;" >
        <div class="test-video-title">
        <h3>Test 1</h3>
        </div>
        <div class="test-video-content">
        <img src="Images/partnerji/default.png" alt="VideolistImg"  />
        </div>
    </a>
    </div>


    <div class="modal fade" id="test-video-1" role="dialog">
        <div class="modal-dialog">
          <div class="modal-content">
            <div class="modal-v-header">
              <button type="button" class="close" data-dismiss="modal">X</button>
              <h3 class="modal-title">Test 1</h3>
            </div>
            <div class="modal-v-body">
                <div class="fb-video" data-href="https://www.facebook.com/facebook/videos/10153231379946729/" data-width="800" data-show-text="true">&#160;</div>
            </div>

          </div>

        </div>
    </div>

1 个答案:

答案 0 :(得分:0)

尝试使用bootstrap中的hidden.bs.modal event。以下是我在相关SO答案中找到的代码示例。

 $(function(){
$('#test-video-1').modal({
    show: false
}).on('hidden.bs.modal', function(){
    $(this).find('.fb-video')[0].pause();
});

});