如何在Javascript中暂停Vimeo视频
How to pause Vimeo video in Javascript?
我会尽可能缩短这个时间,以便快速修复。
我有一个灯箱,打开一个vimeo视频。屏幕右上角有一个按钮可以移除灯箱,但vimeo视频仍在背景中播放,你可以听到,但看不到。我需要能够暂停vimeo的视频,同时隐藏灯箱。
这是我迄今为止的代码:
var lightbox =
'<div id="lightbox">' +
'<a><p id="click-to-close">Click to close</p></a>' +
'<div id="content">' + //insert clicked link's href into img src
' <iframe id="video" src="https://player.vimeo.com/video/131429700?autoplay=1&title=0&byline=0&portrait=0?api=1" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>' +
'</div>' +
'</div>';
$("#click-to-close").click(function() {
$('#lightbox').hide();
var iframe = document.getElementById('video');
// $f == Froogaloop
var player = $f(iframe);
var pauseButton = document.getElementById("click-to-close");
pauseButton.addEventListener("click", function() {
player.api("pause");
});
});
有什么是我遗漏/做错的吗?
您正在点击处理程序中添加一个eventListener,它将隐藏您的按钮。
var lightbox =
'<div id="lightbox">' +
'<a><p id="click-to-close">Click to close</p></a>' +
'<div id="content">' +
' <iframe id="video" src="https://player.vimeo.com/video/131429700?autoplay=1&title=0&byline=0&portrait=0?api=1" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>' +
'</div>' +
'</div>';
$("#click-to-close").click(function() {
// here you hide the pauseButton's container
$('#lightbox').hide();
var iframe = document.getElementById('video');
// $f == Froogaloop
var player = $f(iframe);
var pauseButton = document.getElementById("click-to-close");
// it is now hidden, we can't access it anymore...
pauseButton.addEventListener("click", function() {
player.api("pause");
});
});
所以你有两个解决方案:
- 将您的按钮附加到
#lightbox
元素之外,这似乎很奇怪,因为隐藏的视频仍将播放 - 在第一次单击处理程序中直接调用
player.api("pause");
$("#click-to-close").click(function() {
$('#lightbox').hide();
var iframe = document.getElementById('video');
// $f == Froogaloop
var player = $f(iframe);
player.api("pause");
});
相关文章:
- 如何临时暂停浏览器渲染,然后恢复整个页面
- jQuery循环在特定位置暂停
- NodeJS-readline暂停和恢复事件发射器(逐行读取)
- 最小化时暂停Javascript动画
- jQuery:暂停按钮可以暂停所有其他操作
- tiltSlider播放/暂停视频元素(如果li有当前类)
- Canvas+svg路径动画,在路径中的特定点暂停一段时间,然后继续
- CSS动画暂停并使用javascript播放
- 如何暂停和恢复jquery间隔
- 在FF和IE中使用vimeo播放器的问题-加载flash播放器而不是使用HTML5播放器
- 如何在隐藏时暂停jquery计时器
- 具体化:如何只使用HTML和Javascript制作播放/暂停按钮
- 在 jquery 中定位暂停和播放按钮
- 暂停文档-HTML、CSS、JavaScript
- 如何在悬停时暂停setInterval
- 播放暂停多个Vimeo视频
- 使用Vimeo-api,尝试暂停页面上的所有视频
- 当使用javascript onblur时,在Iframe中暂停youtube和/或vimeo视频
- 如何在Javascript中暂停Vimeo视频
- 暂停youtube和vimeo编程,并检测视频是否正在播放