HTML 5视频OnEnded事件未触发 [英] HTML 5 Video OnEnded Event not Firing

查看:1423
本文介绍了HTML 5视频OnEnded事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图针对视频标记的HTML 5 onended 事件做出反应,但没有成功。在下面的代码片段中,我添加了mouseleave事件以确保jQuery代码正确,并且该事件确实激活了 alert()框。



视频播放正常,但我没有收到 onended 事件(我的 alert()不会触发)。



在Chrome中进行测试,今日更新至5.0.375.55版。

 < HTML> 
< head>
< script src =http://code.jquery.com/jquery-1.4.2.min.js>< / script>
< script>
$(document).ready(function(){
$(#myVideoTag)。bind('mouseleave onended',function(){
alert(All done,function! );
});
});

< / script>
< / head>
< body>
< video id =myVideoTagwidth =640height =360poster =Fractal-zoom-1-04-Snowflake.jpgcontrols>
< source src =Fractal-zoom-1-04-Snowflake.mp4type =video / mp4>< / source>
< source src =Fractal-zoom-1-04-Snowflake.oggtype =video / ogg>< / source>
< / video>

< body>
< html>


解决方案

确保您绑定到结束事件,而不是 onended ,绑定时始终将保留为 jQuery,例如你不能做 .on(onclick),你会做 .on(click)

如果有帮助,可以查看< video> element here: http://www.w3.org/2010/05/video /mediaevents.html


I'm trying to react to the HTML 5 onended event for the video tag without success. In the code snippet below I added the mouseleave event to be sure the jQuery code is correct and that event does activate the alert() box.

The video plays just fine but I am not receiving the onended event (my alert() does not fire).

Testing in Chrome, updated today to version 5.0.375.55.

<html>
<head>
<script src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script>
$(document).ready(function(){
  $("#myVideoTag").bind('mouseleave onended', function(){
        alert("All done, function!");
  });
});

</script>
</head>
<body>
<video id="myVideoTag" width="640" height="360" poster="Fractal-zoom-1-04-Snowflake.jpg" controls>
    <source src="Fractal-zoom-1-04-Snowflake.mp4" type="video/mp4"></source>
    <source src="Fractal-zoom-1-04-Snowflake.ogg" type="video/ogg"></source>
</video>

<body>
<html>

解决方案

Make sure you're binding to the ended event instead of onended, always leave the on out when binding with jQuery, for example you couldn't do .on("onclick"), you'd do .on("click").

If it helps, there's a full listing of available events for the <video> element here: http://www.w3.org/2010/05/video/mediaevents.html

这篇关于HTML 5视频OnEnded事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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