Home > Web Front-end > JS Tutorial > body text

[Javascript] Avoid the phenomenon where the ProgressBar does not move (it only moves after a series of processes are completed)

王林
Release: 2024-08-16 11:27:35
Original
126 people have browsed it

[Javascript] Avoid the phenomenon where the ProgressBar does not move (it only moves after a series of processes are completed)

When you create javascript in html that takes a long time to process, have you ever implemented a ProgressBar and had trouble with the ProgressBar only moving after the entire process was complete?

In this article, I would like to introduce an example of a temporary fix for that situation.

If you follow these steps, the ProgressBar will work during processing.


Step 1: Place the entire process in an async method

First, place the entire process in an async method and execute it.

async function MyFunction(ctx, canvas) {

}

MyFunction(ctx, canvas); // Be sure to run it in the original location.
Copy after login

Step 2: Write a sleep after changing the ProgressBar's Value

Next, write the following after changing the ProgressBar's Value.

const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
await sleep(0);
Copy after login

This will cause the ProgressBar to change during the process.


We have introduced an example of a temporary solution to make the ProgressBar function normally.

I hope this article will help you solve at least one of your struggles.

Thank you for reading.

The above is the detailed content of [Javascript] Avoid the phenomenon where the ProgressBar does not move (it only moves after a series of processes are completed). For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!