HTMLMediaElement: pause event

当暂停媒体播放时 pause 事件触发, 并且媒体进入暂停状态,最常见的是通过pause()方法来触发。 当pause() 触发时pause状态只改变1次,并且媒体的pause变成 true

General info

Bubbles No
Cancelable No
Interface Event
Target Element
Default Action None
Event handler property 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
HTML Living Standard
pause media event
Living Standard
HTML5
pause media event
Recommendation

浏览器兼容性

BCD tables only load in the browser

相关事件

See also