如何使用 jQuery 单击按钮时暂停 YouTube 视频?
我有一个 jQuery 滑块(大部分与 http://slidesjs.com 滑块相同)。当按下“下一个”或“上一个”按钮同时更改幻灯片本身时,如何暂停“当前”或可见幻灯片的 YouTube 视频,我还没有找到答案。我也使用 YouTube 的 iFrame,而不是旧的嵌入代码。
有没有办法用iFrames实现这个功能?我知道 Anything Slider ( http://css-tricks.com/anythingslider-jquery- plugin/ )拥有停止视频的能力,但我不确定它是如何实现的。
这听起来好像可以,但我不确定如何将其与事件结合起来以启动视频暂停功能。
任何帮助将不胜感激。
I have a jQuery slider (mostly identical to the http://slidesjs.com one). I haven't had luck finding an answer to the question of how to pause the "current" or visible slide's YouTube video when the "next" or "previous" button is pressed while also changing the slide itself. I'm using YouTube's iFrames instead of the old embed code, too.
Is there a way to achieve this function with the iFrames? I know that the Anything Slider ( http://css-tricks.com/anythingslider-jquery-plugin/ ) boasts the ability to stop videos, but I'm not sure how it's achieved.
This sounded like it would work, but I'm not sure how to tie it in with an event to set off the video pause function.
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要为您的播放器启用 JS API。
之后,您可以使用
player.pauseVideo()
暂停视频。You need to enable JS API for your player.
After that you can use
player.pauseVideo()
to pause the video.这将重置所有视频的 src,您可以将其修改为仅定位一个
将类“.youtube_video”替换为实际的 iframe 类
This will reset src for all videos, you can modify it to target only one
Replace the class '.youtube_video' with your actual iframe class