私はVimeoモーダルを持っていて、何らかの努力の後で、モーダルが 'X'ボタンで閉じられるとビデオが停止するようになっています。しかし、私は 'X'ボタンに閉じる関数を置くので、ユーザーがボタンを使用するのではなくモーダルを閉じるためにビデオから離れてクリックすると、ビデオは再生を続けます。ブートストラップモーダルが解除されたときにVimeoビデオを停止するには?
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="stopVideo()">
<span aria-hidden="true">×</span>
</button>
</div>
そして、ここでビデオを停止JavaScriptの関数である:ここで
は、私はonclickを持つstopVideo()
関数を呼び出すHTMLがある
<script>
function stopVideo(){
var $frame = $('iframe#nofocusvideo');
// saves the current iframe source
var vidsrc = $frame.attr('src');
// sets the source to nothing, stopping the video
$frame.attr('src','');
// sets it back to the correct link so that it reloads immediately on the next window open
$frame.attr('src', vidsrc);
}
</script>
だから、どのように私は機能を変更することができます特定の閉じるボタンに適用するのではなく、モーダルがフォーカスを失ってビデオから離れてしまうような場合に適用しますか?
私は初心者ですので、簡単に私に行ってください。前もって感謝します!
EDIT 1:
私は、次のようにスクリプトを変更しました:
<script>
function stopVideo(){
var $frame = $('iframe#nofocusvideo');
// saves the current iframe source
var vidsrc = $frame.attr('src');
// sets the source to nothing, stopping the video
$frame.attr('src','');
// sets it back to the correct link so that it reloads immediately on the next window open
$frame.attr('src', vidsrc);
}
$('#promo-video').on('hidden.bs.modal', function (e) {
stopVideo();
})
</script>
stopVideo()
関数が呼び出されていません。私が間違っていることは何か考えていますか?
EDIT 2: ここで問題になっているモーダルのコードがあります:
<!-- VIDEO MODAL -->
<div class="modal fade" id="promo-video" tabindex="-1" role="dialog" aria-labelledby="modal-video-label">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close" onclick="stopVideo()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<div class="modal-video">
<div class="embed-responsive embed-responsive-16by9">
<iframe id="nofocusvideo" src="https://player.vimeo.com/video/180565514?api=1&player_id=vimeoplayer" name="vimeoplayer" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
</div>
</div>
</div>
</div>
</div>
</div>
<!-- End Video Modal -->
あなたが必要とするモーダルイベントについては、hidden.bs.mo dal。 https://getbootstrap.com/javascript/#modals – Bosc
こんにちは@Bosc、私は自分の質問に編集を加えました。それを見てもらえますか?私は何が間違っているのかわからない。 –
ちょうどテストされ、それは私のために働く、あなたがあなたのモーダルに与えたのと同じid#promo-videoであることを確認してください – Bosc