不错的文字特效,逐字变色效果
程序员文章站
2023-11-17 18:29:58
<font color="#669900" style="font-weight:bolder;letter-spacing: 2px;"><script language="javascript">
text = "www.jb51.net";
color1 = "green";
color2 = "red";
speed = 200;
i = 0;
if (navigator.appname == "netscape") {
}
else {
document.write("<span id=a></span>");
}
function changecharcolor() {
if (navigator.appname == "netscape") {
document.a.document.write("<font color=" + color1 + ">");
for (var j = 0; j < text.length; j++) {
if(j == i) {
document.a.document.write("<font color=" + color2 + ">" + text.charat(i) + "</font>");
}
else {
document.a.document.write(text.charat(j));
}
}
document.a.document.write('</font>');
document.a.document.close();
}
if (navigator.appname == "microsoft internet explorer") {
str = "<font color=" + color1 + ">";
for (var j = 0; j < text.length; j++) {
if( j == i) {
str += "<font color=" + color2 + ">" + text.charat(i) + "</font>";
}
else {
str += text.charat(j);
}
}
str += "</font>";
a.innerhtml = str;
}
(i == text.length) ? i=0 : i++;
}
setinterval("changecharcolor()", speed);
// end -->
</script>
</font>
运行效果
[ctrl+a 全选 注:如需引入外部js需刷新才能执行]
text = "www.jb51.net";
color1 = "green";
color2 = "red";
speed = 200;
i = 0;
if (navigator.appname == "netscape") {
}
else {
document.write("<span id=a></span>");
}
function changecharcolor() {
if (navigator.appname == "netscape") {
document.a.document.write("<font color=" + color1 + ">");
for (var j = 0; j < text.length; j++) {
if(j == i) {
document.a.document.write("<font color=" + color2 + ">" + text.charat(i) + "</font>");
}
else {
document.a.document.write(text.charat(j));
}
}
document.a.document.write('</font>');
document.a.document.close();
}
if (navigator.appname == "microsoft internet explorer") {
str = "<font color=" + color1 + ">";
for (var j = 0; j < text.length; j++) {
if( j == i) {
str += "<font color=" + color2 + ">" + text.charat(i) + "</font>";
}
else {
str += text.charat(j);
}
}
str += "</font>";
a.innerhtml = str;
}
(i == text.length) ? i=0 : i++;
}
setinterval("changecharcolor()", speed);
// end -->
</script>
</font>
运行效果
[ctrl+a 全选 注:如需引入外部js需刷新才能执行]
上一篇: 老生常谈onBlur事件与onfocus事件(js)
下一篇: PHP判断图片格式的七种方法小结