HTMLMediaElement
当暂停媒体播放时 pause 事件触发,并且媒体进入暂停状态,最常见的是通过pause()方法来触发。当pause() 触发时pause状态只改变 1 次,并且媒体的pause变成 true。
General info
<table class="properties"> <tbody> <tr> <th scope="row">Bubbles</th> <td>No</td> </tr> <tr> <th scope="row">Cancelable</th> <td>No</td> </tr> <tr> <th scope="row">Interface</th> <td>Event</td> </tr> <tr> <th scope="row">Target</th> <td>Element</td> </tr> <tr> <th scope="row">Default Action</th> <td>None</td> </tr> <tr> <th scope="row">Event handler property</th> <td>GlobalEventHandlers.onpause</td> </tr> <tr> <th scope="row">Specification</th> <td> <a href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#event-media-playing" >HTML5 media</a > </td> </tr> </tbody> </table>
例子
下面例子给媒体添加 pause 事件监听 handler,然后事件发生时会给 handler 发送一个提醒信息
使用 addEventListener():
const video = document.querySelector("video");
video.addEventListener("pause", (event) => {
console.log(
"The Boolean paused property is now true. Either the " +
"pause() method was called or the autoplay attribute was toggled.",
);
});
使用 onpause 事件监听属性:
const video = document.querySelector("video");
video.onpause = (event) => {
console.log(
"The Boolean paused property is now true. Either the " +
"pause() method was called or the autoplay attribute was toggled.",
);
};
规范
浏览器兼容性
相关事件
- HTMLMediaElement.playing_event
- HTMLMediaElement.waiting_event
- HTMLMediaElement.seeking_event
- HTMLMediaElement.seeked_event
- HTMLMediaElement.ended_event
- HTMLMediaElement.loadedmetadata_event
- HTMLMediaElement.loadeddata_event
- HTMLMediaElement.canplay_event
- HTMLMediaElement.canplaythrough_event
- HTMLMediaElement.durationchange_event
- HTMLMediaElement.timeupdate_event
- HTMLMediaElement.play_event
- HTMLMediaElement.pause_event
- HTMLMediaElement.ratechange_event
- HTMLMediaElement.volumechange_event
- HTMLMediaElement.suspend_event
- HTMLMediaElement.emptied_event
- HTMLMediaElement.stalled_event
See also
- HTMLAudioElement
- HTMLVideoElement
- audio
- video
- SpeechSynthesisUtterance
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
