HTMLMediaElement: loadstart-Ereignis
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Das loadstart
-Ereignis wird ausgelöst, wenn der Browser begonnen hat, eine Ressource zu laden.
Syntax
Verwenden Sie den Ereignisnamen in Methoden wie addEventListener()
oder setzen Sie eine Ereignis-Handler-Eigenschaft.
js
addEventListener("loadstart", (event) => {});
onloadstart = (event) => {};
Ereignistyp
Ein generisches Event
.
Beispiele
Live-Beispiel
HTML
html
<div class="example">
<button type="button">Load video</button>
<video controls width="250"></video>
<div class="event-log">
<label for="eventLog">Event log:</label>
<textarea readonly class="event-log-contents" id="eventLog"></textarea>
</div>
</div>
JavaScript
js
const loadVideo = document.querySelector("button");
const video = document.querySelector("video");
const eventLog = document.querySelector(".event-log-contents");
let source = null;
function handleEvent(event) {
eventLog.textContent += `${event.type}\n`;
}
video.addEventListener("loadstart", handleEvent);
video.addEventListener("progress", handleEvent);
video.addEventListener("canplay", handleEvent);
video.addEventListener("canplaythrough", handleEvent);
loadVideo.addEventListener("click", () => {
if (source) {
document.location.reload();
} else {
loadVideo.textContent = "Reset example";
source = document.createElement("source");
source.setAttribute(
"src",
"https://interactive-examples.mdn.mozilla.net/media/cc0-videos/flower.webm",
);
source.setAttribute("type", "video/webm");
video.appendChild(source);
}
});
Ergebnis
Spezifikationen
Specification |
---|
HTML Standard # event-media-loadstart |
HTML Standard # handler-onloadstart |
Browser-Kompatibilität
BCD tables only load in the browser