"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > [Javascript] Avoid the phenomenon where the ProgressBar does not move (it only moves after a series of processes are completed)

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

Published on 2024-08-16
Browse:504

[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.

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);

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.

Release Statement This article is reproduced at: https://dev.to/uni928/javascript-avoid-the-phenomenon-where-the-progressbar-does-not-move-it-only-moves-after-a-series-of-processes- are-completed-26p0?1If there is any infringement, please contact [email protected] to delete it
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3