您的位置:首页 - Javascript
特别的文字霓虹灯js效果

效果如下:
柯乐义 keleyi.com 原文



代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>特别的文字霓虹灯js效果-柯乐义</title>
</head>
<body>
<div><a href="http://keleyi.com" target="_blank">柯乐义</a> keleyi.com <a href="http://keleyi.com/a/bjad/sj995xpd.htm" target="_blank">原文</a></div>
<div id="keleyi" style="font-size:40px;text-align:center"></div>
<script type="text/javascript">
var Tname = "欢迎您访问柯乐义网";
var Tlen = Tname.length;
var TKeleyi = new Array();

for (i = 0; i < Tlen; i++) {
TKeleyi.push(Tname.substring(i, i + 1));
}
var col = new Array("#FFCC00", "#3333FF", "#FF00cc", "#FF0000", "#00ff00", "#CC33FF");

var Kstart = 0;
function Dcolor() {

var Strname = "";
var j;
var ic = 0;
for (i = Kstart; i < Tlen + Kstart; i++) {
j = i;
if (j > Tlen - 1)
j = j - Tlen;
TKeleyi[j] = "<font color=" + col[ic] + ">" + Tname.substring(j, j + 1) + "</font>"
ic = ic + 1;
if (ic == col.length) ic = 0;
}
Kstart = Kstart + 1;
if (Kstart == Tlen) Kstart = 0;
for (i = 0; i < Tlen; i++) {
Strname = Strname + TKeleyi[i];
}
document.getElementById('kel'+'eyi').innerHTML = Strname;

setTimeout("Dcolor()", 600);
}
Dcolor();
</script>
</body>
</html>


使用:
在页面的某处加入以下div代码:
<div id="keleyi" style="font-size:40px;text-align:center"></div>

然后在后面加入脚本代码(只需把文字改成你所需要的):
<script type="text/javascript">
var Tname = "欢迎您访问柯乐义网";
var Tlen = Tname.length;
var TKeleyi = new Array();

for (i = 0; i < Tlen; i++) {
TKeleyi.push(Tname.substring(i, i + 1));
}
var col = new Array("#FFCC00", "#3333FF", "#FF00cc", "#FF0000", "#00ff00", "#CC33FF");

var Kstart = 0;
function Dcolor() {

var Strname = "";
var j;
var ic = 0;
for (i = Kstart; i < Tlen + Kstart; i++) {
j = i;
if (j > Tlen - 1)
j = j - Tlen;
TKeleyi[j] = "<font color=" + col[ic] + ">" + Tname.substring(j, j + 1) + "</font>"
ic = ic + 1;
if (ic == col.length) ic = 0;
}
Kstart = Kstart + 1;
if (Kstart == Tlen) Kstart = 0;
for (i = 0; i < Tlen; i++) {
Strname = Strname + TKeleyi[i];
}
document.getElementById('kel'+'eyi').innerHTML = Strname;

setTimeout("Dcolor()", 600);
}
Dcolor();
</script>

当然你还可以修改颜色和间隔时间等。
本站导航
相关文章
柯乐义 Copyright© keleyi.com