-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
133 lines (99 loc) · 2.5 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
title: "HTMLMediaElement: progress event"
short-title: progress
slug: Web/API/HTMLMediaElement/progress_event
page-type: web-api-event
browser-compat: api.HTMLMediaElement.progress_event
---
{{APIRef}}
The **`progress`** event is fired periodically as the browser loads a resource.
This event is not cancelable and does not bubble.
## Syntax
Use the event name in methods like {{domxref("EventTarget.addEventListener", "addEventListener()")}}, or set an event handler property.
```js
addEventListener("progress", (event) => {});
onprogress = (event) => {};
```
## Event type
A generic {{domxref("Event")}}.
## Examples
### Live example
#### 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>
```
```css hidden
.event-log-contents {
width: 18rem;
height: 5rem;
border: 1px solid black;
margin: 0.2rem;
padding: 0.2rem;
}
.example {
display: grid;
grid-template-areas:
"button log"
"video log";
}
button {
grid-area: button;
width: 10rem;
margin: 0.5rem 0;
}
video {
grid-area: video;
}
.event-log {
grid-area: log;
}
.event-log > label {
display: block;
}
```
#### 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://mdn.github.io/learning-area/html/multimedia-and-embedding/video-and-audio-content/rabbit320.mp4",
);
source.setAttribute("type", "video/mp4");
video.appendChild(source);
}
});
```
#### Result
{{ EmbedLiveSample('Live_example', '100%', '250px') }}
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}
## See also
- {{domxref("HTMLAudioElement")}}
- {{domxref("HTMLVideoElement")}}
- {{HTMLElement("audio")}}
- {{HTMLElement("video")}}