好吧~给你个代码示例:
<div id="ceshi">这里是闪烁的字体!</div><script>
(function(){
var text=document.getElementById("ceshi")
function color(){
if(text.style.color=="red"){
text.style.color="yellow"
}
else{
text.style.color="red"
}
setTimeout(function(){
color()
},200)
}
color()
})()
</script>
不懂的话再问我吧~
function changeCharColor() {//第五行
Text.charAt(i) //改成 text.charAt(i)
其实 navigator.appName == "Netscape" 这个判断大可不必
仅使用以下代码,各主流浏览器均可支持
text = "欢迎光临网页制作特效站"color1 = "blue"
color2 = "red"
fontsize = "6"
speed = 100
i = 0
document.write("<div id=a></div>")
function changeCharColor() {
str = "<center><font face=arial size=" + fontsize + "><font color=" + color1 + ">"
for (var j = 0 j < text.length j++) {
if (j == i) {
str += "<font face=arial color=" + color2 + ">" + text.charAt(i) + "</font>"
} else {
str += text.charAt(j)
}
}
str += "</font></font></center>"
a.innerHTML = str
(i == text.length) ? i = 0 : i++
}
setInterval("changeCharColor()", speed)
//设置闪烁颜色var colors = ['white','black']
//设置闪烁间隔
var frequency = 500
//设置停止时间
var duration = 60000
var text = document.createElement('p')
text.innerHTML = '这里是测试文字'
document.body.innerHTML = ' '
document.body.appendChild(text)
//设置循环间隔
var i = 0
var timer = setInterval(function(){
text.setAttribute('style','color:'+colors[i%colors.length])
//避免变量过大
if(i++>colors.length)i=0
},frequency)
//设置停止时间
setTimeout(function(){clearInterval(timer)},duration)