---
title: 'HTMLMediaElement: pause event'
slug: Web/API/HTMLMediaElement/pause_event
translation_of: Web/API/HTMLMediaElement/pause_event
---
{{APIRef("HTMLMediaElement")}}
当暂停媒体播放时 pause
事件触发, 并且媒体进入暂停状态,最常见的是通过pause()
方法来触发。 当pause()
触发时pause
状态只改变1次,并且媒体的pause
变成 true
。
General info
Bubbles |
No |
Cancelable |
No |
Interface |
{{DOMxRef("Event")}} |
Target |
Element |
Default Action |
None |
Event handler property |
{{domxref("GlobalEventHandlers.onpause")}} |
Specification |
HTML5 media |
例子
下面例子给媒体添加 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.');
};
说明
Specification |
Status |
{{SpecName('HTML WHATWG', "media.html#event-media-pause", "pause media event")}} |
{{Spec2('HTML WHATWG')}} |
{{SpecName('HTML5 W3C', "embedded-content-0.html#event-media-pause", "pause media event")}} |
{{Spec2('HTML5 W3C')}} |
浏览器兼容性
{{Compat("api.HTMLMediaElement.pause_event")}}
相关事件
- {{domxref("HTMLMediaElement.playing_event", 'HTMLMediaElement: playing event')}}
- {{domxref("HTMLMediaElement.waiting_event", 'HTMLMediaElement: waiting event')}}
- {{domxref("HTMLMediaElement.seeking_event", 'HTMLMediaElement: seeking event')}}
- {{domxref("HTMLMediaElement.seeked_event", 'HTMLMediaElement: seeked event')}}
- {{domxref("HTMLMediaElement.ended_event", 'HTMLMediaElement: ended event')}}
- {{domxref("HTMLMediaElement.loadedmetadata_event", 'HTMLMediaElement: loadedmetadata event')}}
- {{domxref("HTMLMediaElement.loadeddata_event", 'HTMLMediaElement: loadeddata event')}}
- {{domxref("HTMLMediaElement.canplay_event", 'HTMLMediaElement: canplay event')}}
- {{domxref("HTMLMediaElement.canplaythrough_event", 'HTMLMediaElement: canplaythrough event')}}
- {{domxref("HTMLMediaElement.durationchange_event", 'HTMLMediaElement: durationchange event')}}
- {{domxref("HTMLMediaElement.timeupdate_event", 'HTMLMediaElement: timeupdate event')}}
- {{domxref("HTMLMediaElement.play_event", 'HTMLMediaElement: play event')}}
- {{domxref("HTMLMediaElement.pause_event", 'HTMLMediaElement: pause event')}}
- {{domxref("HTMLMediaElement.ratechange_event", 'HTMLMediaElement: ratechange event')}}
- {{domxref("HTMLMediaElement.volumechange_event", 'HTMLMediaElement: volumechange event')}}
- {{domxref("HTMLMediaElement.suspend_event", 'HTMLMediaElement: suspend event')}}
- {{domxref("HTMLMediaElement.emptied_event", 'HTMLMediaElement: emptied event')}}
- {{domxref("HTMLMediaElement.stalled_event", 'HTMLMediaElement: stalled event')}}
See also
- {{domxref("HTMLAudioElement")}}
- {{domxref("HTMLVideoElement")}}
- {{HTMLElement("audio")}}
- {{HTMLElement("video")}}
- {{domxref("SpeechSynthesisUtterance")}}