如何在HTML5视频停止播放jQuery时收听?

时间:2014-08-29 14:35:55

标签: javascript jquery html5 html5-video

我发现了这个similar question here,但答案在我的情况下不起作用。

我的JsFiddle:http://jsfiddle.net/leongaban/yvne6fnt/

HTML

<div style="position: fixed; top: 0; width: 100%; height: 100%; z-index: -1;">
<video id="hero_video" controls="" autoplay="autoplay" preload poster="http://media.w3.org/2010/05/sintel/poster.png" style="width:100%; height:100%">
    <source id="mp4" src="http://leongaban.com/v6/videos/clouds.mp4" type="video/mp4">
  <source id="webm" src="http://leongaban.com/v6/videos/clouds.webm" type="video/webm">
  <source id="ogv" src="http://leongaban.com/v6/videos/clouds.ogv" type="video/ogg">
  <p>Your user agent does not support the HTML5 Video element.</p>
</video>

JS

$("#hero_video").bind('stop', function(e) {
    console.log('stopped');
    alert('stopped');
}, true);

/*
$("video").bind('stop', function(e) {
    console.log('stopped');
    alert('stopped');
}, true);
*/

1 个答案:

答案 0 :(得分:1)

如果从函数中删除第三个参数,则此方法有效:

$("#hero_video").bind('stop', function(e) {
    console.log('stopped');
    alert('stopped');
});

请注意,这只会在视频的开头和视频中触发。如果您还想在暂停时触发事件,则还必须包括暂停事件:

$("#hero_video").bind('stop pause', function(e) {
    console.log('stopped');
    alert('stopped');
});

JsFiddle:http://jsfiddle.net/yvne6fnt/8/

不确定为什么会这样,因为该参数的默认值为truehttp://api.jquery.com/bind/