自动变色的文字

2008-09-20 08:47:00 | 【

文字会自动改变颜色,不断的闪烁,放在网页里非常醒目

查看全部代码 View Code

第一步:
在<head>区添加以下脚本定义

<Script language="JavaScript">

        /*****************************************************
         *  Share JavaScript (http://www.ShareJS.com)
         * 使用此脚本程序,请保留此声明
         * 获取此脚本以及更多的JavaScript程序,请访问 http://www.ShareJS.com
         ******************************************************/
    
var someText = "Welcome to my Website!!";	// 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>


第二步:
为<body>添加OnLoad事件,当页面加载的时候便可以执行脚本函数
<body bgcolor="#000000" text="#ffffff" onLoad="loadText()">


第三步:
在需要显示效果的地方加上定义,系统会查找ID为textDiv的标签
<div id="textDiv"></div>


注:如果把网页背景设置为黑色,效果会更明显

下载"自动变色的文字"

  • 本地下载
  • 本地下载2
上一篇: 点击改变样式  
下一篇: 类似荧光灯的文字效果

相关资源