If you have played a table tennis game, you will not be unfamiliar with the concept of strength bar, such:
There are also vertical intensity bars, such:
In fact, similar articles are everywhere! For example, the progress bar when you enter the game, the entries read by the mage in the World of Warcraft, and so on.
By introducing jquery ui, we can easily get the following static strength:
Html:
- <div class="progressbar" style="width: 20%"></div>
Js:
- $(function () {
- $(".progressbar").progressbar({
- value: 37
- });
Add Jscex to make it work:
- <Script type = "text/javascript">
- $ (Function (){
- $ (". Progressbar"). progressbar ({
- Value: 5
- });
- });
- Var executeAsync = eval (Jscex. compile ("async", function (proceedValues ){
- While (proceedValues <100 ){
- ProceedValues ++;
- $ Await (Jscex. Async. sleep (50 ));
- $ (". Progressbar"). progressbar ({
- Value: proceedValues
- });
- }
- }));
- Function btnExecuteAsync_onclick (){
- ExecuteAsync (5). start ();
- }
- </Script>
- <Div class = "progressbar" style = "width: 20%">
- </Div>
- <Input id = "btnExecuteAsync" type = "button" value = "start" onclick = "return btnExecuteAsync_onclick ()"/>
But in general, we need to round-trip infinite loops, so we should achieve this:
- var executeAsync = eval(Jscex.compile("async", function (proceedValues) {
- while (true) {
- while (proceedValues < 100) {
- proceedValues++;
- $await(Jscex.Async.sleep(10));
- $(".progressbar").progressbar({
- value: proceedValues
- });
- }
- if (proceedValues == 100) {
- while (proceedValues > 0) {
- proceedValues--;
- $await(Jscex.Async.sleep(10));
- $(".progressbar").progressbar({
- value: proceedValues
- });
- }
- }
- }
- }));
At this time, I accidentally commented out if (proceedValues = 100) {} and the code looked like this:
- var executeAsync2 = eval(Jscex.compile("async", function (proceedValues) {
- while (true) {
- while (proceedValues < 100) {
- proceedValues++;
- $await(Jscex.Async.sleep(10));
- $(".progressbar3").progressbar({
- value: proceedValues
- });
- }
- //if (proceedValues == 100) {
- while (proceedValues > 0) {
- proceedValues--;
- $await(Jscex.Async.sleep(10));
- $(".progressbar3").progressbar({
- value: proceedValues
- });
- }
- //}
- }
- }));
The results are exactly the same. No error!
It can be seen that the two internal while statements are not executed at the same time, but are very linear. They wait for each other, and the initial execution order is from top to bottom. The internal while statements are executed completely, then jump to the outermost while and re-execute.
This design method is undoubtedly elegant !!
The above three while methods have good semantics. From the analysis, we can see that,Code can also be written like this: