使用Foundation 6显示模式自动播放YouTube视频

时间:2016-12-22 17:00:21

标签: youtube-api zurb-foundation zurb-reveal

我进行了搜索和搜索,但只能找到关于此类事情的非常老的帖子。我要做的是创建多个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>

Codepen

1 个答案:

答案 0 :(得分: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');