Jqurey + Jscex build the game strength bar, jqureyjscex

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.