【发布时间】:2018-07-21 20:24:16
【问题描述】:
我有一个 html5 视频元素,我想在页面加载时播放。 每次播放视频后,我都想为不同的东西添加更多代码。
出于某种原因,.trigger("play") 使视频播放两次。 如果我暂停它并从 html 控件再次播放它会播放一次。 我不明白为什么初始触发器会使视频播放两次。 我只需要它运行一次。
html:
<video width="320" height="240" controls >
<source src="http://techslides.com/demos/sample-videos/small.mp4" type="video/mp4">
Your browser does not support the video tag.
</video>
jquery:
var triggerCount = 0;
$("video").on("play", function () {
console.log(++triggerCount);
//do more stuff here
})
$("video").trigger("play");
代码示例:jsFiddle
【问题讨论】:
标签: javascript jquery html5-video