现在的位置: 首页 > 综合 > 正文

一个文字的特效,两种颜色,来回闪动。

2012年11月30日 ⁄ 综合 ⁄ 共 1142字 ⁄ 字号 评论关闭

<html>
<head>
<title></title>
<Script language="JavaScript">
var someText = "欢迎来到中能电力科技开发有限公司"; // the text
var aChar;
var aSentence;
var i=0;     // a counter
var colors = new Array("EFEFEF","164781"); // the colors
var aColor;     // the chosen color

function loadText(){
 aColor="164781"
 // randomly choose color
 aChar = someText.charAt(i);
 if (i==0)
  aSentence = aChar;
 else
  aSentence += aChar; 
 // 50 iterations max.
 if (i < 20) {
  i++;
 }
 else{
  aColor = colors[Math.floor(Math.random()*colors.length)];
 }
 // For IE
  if (document.all){
   textDiv.innerHTML= "<font color='#"+aColor+"' style='font-size:12px'>"+aSentence+"</font>";
   setTimeout("loadText()",300);
  }
  // For Netscape Navigator 4
  else if (document.layers){
   document.textDiv.document.write("<font color='#"+aColor+"' style='font-size:12px'>"+aSentence+"</font>");
   document.textDiv.document.close();
   setTimeout("loadText()",300);
  }
  // For other
  else if (document.getElementById){
   document.getElementById("textDiv").innerHTML = "<font color='#"+aColor+"' style='font-size:12px'>"+aSentence+"</font>";
   setTimeout("loadText()",300);
  }
}
</SCRIPT>
<div id="textDiv" style="font-size:12px"></div>
 
</head>
<body onLoad="loadText()">

</body>
</html>

抱歉!评论已关闭.