如何使用 jQuery 停止 Vimeo 视频
当我隐藏 YouTube 视频时,它会停止播放。然而,Vimeo 视频的情况并非如此。还有其他方法可以停止 Vimeo 视频吗?
When I hide a YouTube video, it stops playing. However, this is not the case for Vimeo videos. Is there another way to stop a Vimeo video?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
首先,将 ID 添加到您的 iFrame。然后将其添加到您的 javascript 关闭窗口单击函数中:
First, add an ID to your iFrame. Then add this to your javascript close window click function:
最近,当模式关闭时,我需要暂停 Bootstrap 模式内的 Vimeo 视频。
Vimeo 视频嵌入到 iframe 中。
这对我有用:
I recently needed to pause a Vimeo video that was inside a Bootstrap modal when the modal was closed.
The Vimeo video was embedded in an iframe.
This is what worked for me:
Vimeo 有JavaScript API,允许您访问和调用视频上的许多属性和方法播放器(包括暂停视频并完全卸载)。他们还有一个 API Playground 和一些 GitHub 上的示例。
[编辑]
既然您提到您使用通用嵌入代码,那么以下是该网站的一些注意事项:
Vimeo has a JavaScript API that allows you to access and invoke many properties and methods on the video player (including pausing the video and also unloading it completely). They also have an API Playground and some examples on GitHub.
[Edit]
Since you mention that you use the Universal Embed Code, here are some caveats from the web site:
要恢复 SRC 属性,请在清除之前使用以下命令:
接下来,SRC 属性清除:
回调之前的 SRC 属性:
To restore the SRC attribute, use the following before clearing:
Next, SRC attribute clear:
Callback previous SRC attribute:
与 David 类似的另一个答案...您可以使用 jQuery 清除 iFrame 的 SRC 属性。
我将其与 Vimeo 视频和灯箱效果一起使用。当灯箱再次触发时,我将视频 URL 添加回 iFrame SRC,然后再显示。
Another answer along the lines of David's...you can use jQuery to clear the SRC attribute of the iFrame.
I'm using this with a Vimeo video and a lightbox effect. When the lightbox is triggered again, I add the video URL back to the iFrame SRC before showing it.
使用 Vimeo JavaScript API,可以通过以下方式完成:
https://github。 com/vimeo/player.js#unload-promisevoid-error
Using the Vimeo JavaScript API, it can be done with:
https://github.com/vimeo/player.js#unload-promisevoid-error
您必须删除并重新安装 src。
You have to remove and put the src back on.