0

我已经搜索和搜索,但只能找到关于这类事情的非常古老的帖子。我要做的是创建多个 Foundation 6 Reveal 模态,这些模态会打开将自动播放的 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>

密码笔

4

1 回答 1

2

我会通过 JS 创建 Reveal 模式并使用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');
于 2016-12-23T03:46:44.170 回答