70、颜色变化的欢迎词

70、颜色变化的欢迎词

脚本说明:

第一步:把如下代码加入<body>区域中

<Script language="JavaScript">

 

var someText = "Welcome to www.7stk.com";     // the text

var aChar;

var aSentence;

var i=0;                               // a counter

 

var colors = new Array("FF0000","FFFF66","FF3399","00FFFF","FF9900","00FF00"); // the colors

var aColor;                                 // the chosen color

 

function loadText()

{

       // randomly choose color

       aColor = colors[Math.floor(Math.random()*colors.length)];

 

       aChar = someText.charAt(i);

       if (i == 0)

              aSentence = aChar;

       else

              aSentence += aChar;     

 

       // 50 iterations max.

       if (i < 50)       i++;

      

       // For IE

       if (document.all)

       {

              textDiv.innerHTML= "<font color='#"+aColor+"' face='Tahoma' size='5'><i>"+aSentence+"</i></font>";

              setTimeout("loadText()",100);

       }

             

       // For Netscape Navigator 4

       else if (document.layers)

       {

              document.textDiv.document.write("<font color='#"+aColor+"' face='Tahoma'                                                    size='5'><i>"+aSentence+"</i></font>");

              document.textDiv.document.close();

              setTimeout("loadText()",100);

       }

             

       // For other

       else if (document.getElementById)

       {

              document.getElementById("textDiv").innerHTML = "<font color='#"+aColor+"'                  face='Tahoma'size='5'><i>"+aSentence+"</i></font>";

              setTimeout("loadText()",100);

       }

}

</SCRIPT>

<div id="textDiv"></div>

 

第二步:把<body>中的内容改为:

<body  onLoad="loadText()">

 

Write a comment

Comments: 0