Saturday, 3 December 2011

Javascript Acceleration


<html>  
<head>  
  <script type="text/javascript">  
var c=-1;  
var tmr;  
ntimer=1000;  
var ArrColor=new Array();  
ArrColor[0]="green";  
ArrColor[1]="blue";  
ArrColor[2]="red";  
ArrColor[3]="#ffffff";  
function showpos()  
{  
if(c==3) c=0;  
else c++;  
if(ntimer<=5) ntimer=1000;  
else ntimerntimer = ntimer-5;  
document.body.style.backgroundColor=ArrColor[c];  
clearTimeout(tmr);  
tmr=setTimeout("showpos()", ntimer);  
}    
tmr=setTimeout("showpos()", ntimer);  
</script>  
</head>  
 <body>  
<p>Run this program, and watch it accelerate, slowly and slowly.</p>  
</body>  
</html> 


No comments:

Post a Comment

Visual comparison of the two methods, creating a simple table.

Option 1, using PHP: // PHP $html = '<table>' ;     foreach ( $data as $row ) {     $html .= '<tr>...