带有基础6的自动播放YouTube视频揭示了模式



我已经搜索和搜索过,但只能找到有关此类内容的非常旧的帖子。我要做的是创建多个Foundation 6揭示了打开YouTube视频的模式,该视频将自动播放,并在模态关闭时停止视频/音频。

这是一个基本设置。任何帮助都很好!

<p><a data-open="videoModal-01">Click me for a modal 01</a></p>
<p><a data-open="videoModal-02">Click me for a modal 02</a></p>
<!-- modal 01 -->
<div class="reveal" id="videoModal-01" data-reveal>
  <div class="responsive-embed">
    <iframe width="560" height="315" src="https://www.youtube.com/embed/4krs7z2bjlE" frameborder="0" allowfullscreen></iframe>
  </div>
  <button class="close-button" data-close aria-label="Close modal" type="button">
    <span aria-hidden="true">&times;</span>
  </button>
</div>
<!-- modal 2 -->
<div class="reveal" id="videoModal-02" data-reveal>
  <div class="responsive-embed">
    <iframe width="560" height="315" src="https://www.youtube.com/embed/c8aFcHFu8QM" frameborder="0" allowfullscreen></iframe>
  </div>
  <button class="close-button" data-close aria-label="Close modal" type="button">
    <span aria-hidden="true">&times;</span>
  </button>
</div>

codepen

我将通过JS创建揭示模式,并使用YouTube iframe player API创建,加载,启动和停止视频。这是一个让您入门的部分原型(它缺少播放器功能)。

var $dialog = $('#revealDialog');
if ($dialog.length === 0) {
    // init dialog
    $dialog = $('<div id="revealDialog" class="reveal dialog" data-reveal><div id="revealDialogContent"></div>');
    new Foundation.Reveal($dialog);
    // attach to to-be-loaded dialog close button(s) 
    $(document).on('click', '.button-dialog-close', function () {
        //stop player, e.g. player.stopVideo(); 
        $dialog.foundation('close');
        return false;
    });
}
// set dialog's content
$('#revealDialogContent').html('<div id="player"></div><button class="close-button" data-close aria-label="Close modal" type="button"><span aria-hidden="true">&times;</span>');
// create player and play it on the ready event
// player = new YT.Player('player'.....
// show it modal
$dialog.foundation('open');

相关内容

  • 没有找到相关文章

最新更新