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():

js
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 事件监听属性:

js
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
HTML Standard
# event-media-pause
HTML Standard
# handler-onpause

浏览器兼容性

BCD tables only load in the browser

相关事件

See also