使用JQuery播放/暂停HTML 5视频 [英] Play/pause HTML 5 video using JQuery

查看:195
本文介绍了使用JQuery播放/暂停HTML 5视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用JQuery控制HTML5视频。我有一个选项卡式界面中有两个剪辑,共有六个选项卡,其他只有图像。我试图让他们的选项卡点击时播放视频剪辑,然后停止,当其他任何人点击。

I am trying to control HTML5 videos using JQuery. I have two clips in a tabbed interface, there are six tabs in total, the others just have images. I am trying to make the video clips play when their tab is clicked and then stop when any of the others are clicked.

这必须是一件简单的事情,但我似乎无法让它工作,我使用的代码播放视频是:

This must be a simple thing to do but I cant seem to get it to work, the code I am using to play the video is:

$('#playMovie1').click(function(){
  $('#movie1').play();
      });

我已经读过视频元素需要在一个函数中暴露才能控制它,找不到一个例子。我可以使用JS:

I have read that the video element needs to be exposed in a function to be able to control it but can't find an example. I am able to make it work using JS:

document.getElementById('movie1').play();

任何建议都是很好的。感谢

Any advice would be great. Thanks

推荐答案

您的解决方案在此显示问题 - play 一个jQuery函数,但是一个DOM元素的函数。因此,您需要在DOM元素上调用它。你给出一个例子,说明如何使用本地DOM函数。 jQuery等效 - 如果你想这样做以适应现有的jQuery选择 - 将 $('#videoId')。get(0).play()。 ( get 从jQuery选择中获取本机DOM元素。)

Your solution shows the issue here -- play is not a jQuery function but a function of the DOM element. You therefore need to call it upon the DOM element. You give an example of how to do this with the native DOM functions. The jQuery equivalent -- if you wanted to do this to fit in with an existing jQuery selection -- would be $('#videoId').get(0).play(). (get gets the native DOM element from the jQuery selection.)

这篇关于使用JQuery播放/暂停HTML 5视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆