帮忙解释一下动态走马灯的算法!
程序代码:
<body bgcolor="#fef4d9" OnLoad="stack()"> <SCRIPT LANGUAGE="JavaScript"> <!-- hide script from old browsers var phrase = "精彩javascript特效!!!"; var lenPhrase = phrase.length; var phraseOut = ""; var pause = 25; var i=0; var j=0; var animateWidth = 20; var position=animateWidth; function stack() { if (phrase.charAt(i) != " ") { phraseOut = ""; for (j=0; j<i; j++) { phraseOut += phrase.charAt(j); } for (j=i; j<position; j++) { phraseOut += " "; } phraseOut += phrase.charAt(i); for (j=position; j<animateWidth; j++) { phraseOut += " "; } window.status = phraseOut; if (position == i) { animateWidth++; position = animateWidth; i++; } else { position--; } } else { i++ } if (i<lenPhrase) { setTimeout("stack()",pause); } } // end hiding contents --> </SCRIPT> </body>
看了一个多小时还没有看懂!