HTMLMediaElement
durationchange 事件会在 duration 属性更新时被触发。
<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.ondurationchange </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>
例子
下面的例子为 HTMLMediaElement 的 durationchange 事件添加事件监听器,然后在事件触发时发送一个消息。
使用 addEventListener():
const video = document.querySelector("video");
video.addEventListener("durationchange", (event) => {
console.log("Not sure why, but the duration of the video has changed.");
});
使用 ondurationchange 事件处理器属性:
const video = document.querySelector("video");
video.ondurationchange = (event) => {
console.log("Not sure why, but the duration of the video has changed.");
};
Specifications
Browser compatibility
Related Events
- 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
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
