不错的文字特效,逐字变色效果
程序员文章站
2022-06-19 19:37:44
<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需刷新才能执行]
上一篇: 花菜和虾能一起吃吗,这个答案会惊到你吗
下一篇: 白糖姜茶你喝过吗