jquery+Jscex打造游戲力度條
本文介紹了jquery+Jscex打造游戲力度條,如果大家玩過桌球類游戲的話,對力度條的概念一定不會陌生,如下圖:

其實(shí),類似的條條無處不在!比如進(jìn)游戲時候的進(jìn)度條、魔獸世界里法師施法過程中讀的條等等······
引入jquery ui,我們可以輕松得到下面這個靜止的力度條:
html:
<div class="progressbar" style="width: 20%"></div>
js:
$(function () {
$(".progressbar").progressbar({
value: 37
});
加入Jscex讓它動起來:
<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="開始" onclick="return btnExecuteAsync_onclick()" />
但是通常情況下,我們需要它往返無限循環(huán)下去,那么我們應(yīng)該這么實(shí)現(xiàn):
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
});
}
}
}
}));
就在這個時候,我一不小心,把if (proceedValues == 100) { } 注釋掉了,代碼變成這個樣子:
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
});
}
//}
}
}));
效果上面一模一樣,不會錯!
可以看得出來,內(nèi)部的兩個while不是同時執(zhí)行的,而是非常線性的,它們之間會相互等待,而且最開始的執(zhí)行順序是從上至下,內(nèi)部的while執(zhí)行完了,再跳到最外層的while重新執(zhí)行。
這種設(shè)計(jì)方式,無疑是優(yōu)雅的?。?/p>
上面那種三個while的方式語意性很好,從剛剛分析得出,代碼還可以這樣寫:
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
});
}
}
}
}));
這樣相當(dāng)于永遠(yuǎn)跳不出最外層的proceedValues < 100,所以也會無限循環(huán)下去。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<script src="http://files.cnblogs.com/iamzhanglei/jscex.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" media="all" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js" type="text/javascript"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js" type="text/javascript"></script>
<script>
$(function () {
$("#progressbar3").progressbar({
value: 37
});
});
</script>
<div class="demo">
<div id="progressbar3" style="width:200px"></div>
</div><!-- End demo -->
<script>
var executeAsync21 = eval(Jscex.compile("async", function (proceedValues) {
while (true) {
while (proceedValues < 100) {
proceedValues++;
$await(Jscex.Async.sleep(100));
$("#progressbar3").progressbar({
value: proceedValues
});
}
//if (proceedValues == 100) {
while (proceedValues > 0) {
proceedValues--;
$await(Jscex.Async.sleep(100));
$("#progressbar3").progressbar({
value: proceedValues
});
}
//}
}
}));
executeAsync21(38).start();
</script>
</body>
</html>
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于jQuery排序及應(yīng)用實(shí)現(xiàn)Tab欄特效
這篇文章主要介紹了基于jQuery排序及應(yīng)用實(shí)現(xiàn)Tab欄特效,jquery是基于JavaScript語言寫出來的一個框架,它封裝JavaScript常用的功能代碼,提供一種簡便的JavaScript設(shè)計(jì)模式,但實(shí)質(zhì)上還是js,所以JQuery也屬于網(wǎng)頁編程語言。下面更多內(nèi)容需要的小伙伴可以參考一下2022-03-03
基于jquery實(shí)現(xiàn)的鼠標(biāo)懸停提示案例
本文主要介紹了基于jquery實(shí)現(xiàn)的鼠標(biāo)懸停提示的詳細(xì)案例。代碼全面,功能實(shí)用,需要的朋友可以參考借鑒2016-12-12
jQuery實(shí)現(xiàn)邊框動態(tài)效果的實(shí)例代碼
這篇文章給大家分享了一個jQuery邊框動態(tài)的效果,當(dāng)鼠標(biāo)移動到邊框區(qū)域的時候,邊框會有個動態(tài)的加載動畫效果,實(shí)現(xiàn)的效果真的非常不錯,下面來一起看看吧。2016-09-09
Jquery使用each函數(shù)實(shí)現(xiàn)遍歷及數(shù)組處理
這篇文章主要介紹了Jquery使用each函數(shù)實(shí)現(xiàn)遍歷及數(shù)組處理,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-07-07
基于Jquery實(shí)現(xiàn)焦點(diǎn)圖淡出淡入效果
這篇文章主要介紹了基于Jquery實(shí)現(xiàn)焦點(diǎn)圖淡出淡入效果,需要的朋友可以參考下2015-11-11
DIV隨滾動條滾動而滾動的實(shí)現(xiàn)代碼【推薦】
下面小編就為大家?guī)硪黄狣IV隨滾動條滾動而滾動實(shí)現(xiàn)代碼【推薦】。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-04-04
JQuery基于FormData異步提交數(shù)據(jù)文件
這篇文章主要介紹了JQuery基于FormData異步提交數(shù)據(jù)文件,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友可以參考下2020-09-09

