状态栏慢慢计算Pi值 - 中国WEB开发者网络 (http://www.webasp.net) -- 网页特效 (http://www.webasp.net/javascript/) --- 状态栏慢慢计算Pi值 (http://www.webasp.net/javascript/1/513.htm) |
| -- 发布日期: 2005-06-15 |
| <!-- 网页特效代码由[中国WEB开发者网络:http://www.ChinaWebDev.com]提供! --> <!-- 要实现此效果需要 1 个步骤: --> <!-- 第 1 步: --> <!-- 把下面的代码加到<BODY></BODY>区域中: --> <script> <!-- function pi(name){ this.init = init; this.compNext = p_compNext; this.printPi = p_printPi; this.computePi = p_computePi; this.runs = new Number(); this.data = new Number(); this.sign = new Number(); this.name = name; //this.init(); } function init(){ this.runs = -1; this.data = 0; this.sign = -1; } function p_computePi(delay){ //eval(this.name+".compNext();"); this.compNext(); if (this.runs %100 == 0) this.printPi(); //eval(this.name+".printPi();"); setTimeout(this.name + ".computePi("+delay+")",delay); } function p_printPi(){ //document.pi.pivalue.value = this.data * 4; window.status = "[" + this.runs + "] > " + this.data * 4; //document.pi.runs.value = this.runs; } function p_compNext(){ this.sign = parseInt(this.sign) * -1; this.runs = parseInt(this.runs) + 1; this.data += Math.pow((parseInt(this.runs) * 2 + 1),-1) * this.sign; } myPi = new pi("myPi"); myPi.init(); myPi.computePi(1); //--> </script> |
| webasp.net |