ProgressEvent
The ProgressEvent
interface represents events measuring progress of an underlying process, like an HTTP request (for an XMLHttpRequest
, or the loading of the underlying resource of an <img>
(en-US), <audio>
(en-US), <video>
(en-US), <style>
(en-US) or <link>
(en-US)).
建構式
ProgressEvent()
(en-US)-
Creates a
ProgressEvent
event with the given parameters.
屬性
Also inherits properties from its parent Event
.
ProgressEvent.lengthComputable
(en-US) Read only-
Is a
Boolean
(en-US) 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. ProgressEvent.loaded
(en-US) Read only-
Is an
unsigned long long
representing the amount of work already performed by the underlying process. The ratio of work done can be calculated with the property andProgressEvent.total
. When downloading a resource using HTTP, this only represent the part of the content itself, not headers and other overhead. ProgressEvent.total
(en-US) Read only-
Is an
unsigned long long
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.
方法
Also inherits methods from its parent Event
.
ProgressEvent.initProgressEvent()
(en-US) 已棄用 非標準-
Initializes a
ProgressEvent
created using the deprecatedDocument.createEvent("ProgressEvent")
method.
範例
The following example adds a ProgressEvent
to a new XMLHTTPRequest
and uses it to display the status of the request.
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();
規格
Specification |
---|
XMLHttpRequest Standard # interface-progressevent |
瀏覽器相容性
BCD tables only load in the browser
參見
- The
Event
base interface.