【发布时间】:2017-02-20 01:04:12
【问题描述】:
我想用 Youtube 视频创建一个 Slick 滑块,所以我可以直接使用 youtube iFrame 嵌入代码到幻灯片,它会工作,但我想要实现的是当幻灯片更改时,视频应该停止/暂停播放。
我正在使用 Slick Slider。
这是我正在使用的 HTML::
<div class="entry_slider_video">
<div data-thumb="http://placehold.it/140x100">
<iframe width="560" height="315" src="https://www.youtube.com/embed/gLJdzky63BA" frameborder="0" allowfullscreen></iframe>
</div>
<div data-thumb="http://placehold.it/140x100"><iframe width="420" height="315" src="https://www.youtube.com/embed/Tf4sa0BVJVw?rel=0&enablejsapi=1" frameborder="0" allowfullscreen></iframe>
</div>
<div data-thumb="http://placehold.it/140x100">
<iframe width="420" height="315"src="https://www.youtube.com/embed/QF903RaKLvs?rel=0&enablejsapi=1" frameborder="0" allowfullscreen>
</iframe>
</div>
还有 JS:::
$('.entry_slider_video').slick({
arrows: false,
fade: true,
autoplay: true,
dots: true,
customPaging : function(slider, i) {
var thumb = $(slider.$slides[i]).data('thumb');
return '<a class="enty_thumbs"><img src="'+thumb+'"></a>';
}
});
我知道我必须使用 Youtube API(https://developers.google.com/youtube/iframe_api_reference) 来实现这一点,我尝试了一些 SO 的解决方案,但没有运气。任何帮助将不胜感激,谢谢。
【问题讨论】:
标签: jquery youtube slick.js youtube-iframe-api