--- 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")}}

相关事件

See also