Skip to content

Commit

Permalink
Adding an example to ProgressEvent constructor (mdn#31334)
Browse files Browse the repository at this point in the history
* adding-a-event-progress-constructor-example

* Apply suggestions from code review

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update index.md

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Joshua Chen <[email protected]>
  • Loading branch information
3 people authored Jan 20, 2024
1 parent be67744 commit 6c65e4c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions files/en-us/web/api/progressevent/progressevent/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,28 @@ new ProgressEvent(type, options)

A new {{domxref("ProgressEvent")}} object.

## Example

The example demonstrates how a `ProgressEvent` is built using a constructor. This is particularly useful for tracking the progress of processes like file uploads, downloads, or any long-running tasks.

```js
function updateProgress(loaded, total) {
const progressEvent = new ProgressEvent("progress", {
lengthComputable: true,
loaded: loaded,
total: total,
});

document.dispatchEvent(progressEvent);
}

document.addEventListener("progress", (event) => {
console.log(`Progress: ${event.loaded}/${event.total}`);
});

updateProgress(50, 100);
```

## Specifications

{{Specifications}}
Expand Down

0 comments on commit 6c65e4c

Please sign in to comment.