Jqurey + Jscex build the game strength bar, jqureyjscex
This article introduces jqurey + Jscex to create a strong game. If you have played a table tennis game, you will not be unfamiliar with the concept of strong bars, such:
In fact, similar articles are everywhere! For example, the progress bar when you enter the game, the bar read during the mage's trial in 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, the code can also be written as follows:
var executeAsync = eval(Jscex.compile("async", function (proceedValues) { 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 }); } } }}));
This is equivalent to Never jumping out of the outermost proceedValues <100, so it will go through an infinite loop.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.