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
|
---
title: ProgressEvent
slug: Web/API/ProgressEvent
translation_of: Web/API/ProgressEvent
---
<p>{{APIRef("DOM Events")}}</p>
<p>The <strong><code>ProgressEvent</code></strong> interface represents events measuring progress of an underlying process, like an HTTP request (for an <code>XMLHttpRequest</code>, or the loading of the underlying resource of an {{HTMLElement("img")}}, {{HTMLElement("audio")}}, {{HTMLElement("video")}}, {{HTMLElement("style")}} or {{HTMLElement("link")}}).</p>
<h2 id="建構式">建構式</h2>
<dl>
<dt>{{domxref("ProgressEvent.ProgressEvent", "ProgressEvent()")}}</dt>
<dd>Creates a <code>ProgressEvent</code> event with the given parameters.</dd>
</dl>
<h2 id="屬性">屬性</h2>
<p><em>Also inherits properties from its parent {{domxref("Event")}}</em>.</p>
<dl>
<dt>{{domxref("ProgressEvent.lengthComputable")}} {{readonlyInline}}</dt>
<dd>Is a {{domxref("Boolean")}} flag indicating if the total work to be done, and the amount of work already done, by the underlying process is calculable. In other words, it tells if the progress is measurable or not.</dd>
<dt>{{domxref("ProgressEvent.loaded")}} {{readonlyInline}}</dt>
<dd>Is an <code>unsigned long long</code> representing the amount of work already performed by the underlying process. The ratio of work done can be calculated with the property and <code>ProgressEvent.total</code>. When downloading a resource using HTTP, this only represent the part of the content itself, not headers and other overhead.</dd>
<dt>{{domxref("ProgressEvent.total")}} {{readonlyInline}}</dt>
<dd>Is an <code>unsigned long long</code> representing the total amount of work that the underlying process is in the progress of performing. When downloading a resource using HTTP, this only represent the content itself, not headers and other overhead.</dd>
</dl>
<h2 id="方法">方法</h2>
<dl>
</dl>
<p><em>Also inherits methods <em>from its parent {{domxref("Event")}}.</em></em></p>
<dl>
<dt>{{domxref("ProgressEvent.initProgressEvent()")}} {{deprecated_inline}}{{non-Standard_inline}}</dt>
<dd>Initializes a <code>ProgressEvent</code> created using the deprecated {{domxref("Document.createEvent()", "Document.createEvent(\"ProgressEvent\")")}} method.</dd>
</dl>
<h2 id="範例">範例</h2>
<p>The following example adds a <code>ProgressEvent</code> to a new {{domxref("XMLHTTPRequest")}} and uses it to display the status of the request.</p>
<pre class="brush: js"> var progressBar = document.getElementById("p"),
client = new XMLHttpRequest()
client.open("GET", "magical-unicorns")
client.onprogress = function(pe) {
if(pe.lengthComputable) {
progressBar.max = pe.total
progressBar.value = pe.loaded
}
}
client.onloadend = function(pe) {
progressBar.value = pe.loaded
}
client.send()</pre>
<h2 id="規格">規格</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Status</th>
<th scope="col">Comment</th>
</tr>
<tr>
<td>{{SpecName('Progress Events', '#interface-progressevent', 'ProgressEvent')}}</td>
<td>{{Spec2('Progress Events')}}</td>
<td>Initial definition.</td>
</tr>
</tbody>
</table>
<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
{{Compat("api.ProgressEvent")}}
<h2 id="參見">參見</h2>
<ul>
<li>The {{domxref("Event")}} base interface.</li>
</ul>
|