走到函数t了,但是,你的t里面没有写闪烁的动作啊,你的t只是把颜色变成蓝色。并没有闪烁。
function qq() {this.s = 0
this.t = 3
this.u = function () {
if(this.s% 2==0){
can.strokeStyle = 'blue'
}else{
can.strokeStyle = 'red'
}
can.strokeText(str, 40, 50)
}
}
我给你吧qq函数重写了一下,你替换一下。就闪烁了。
<!doctype html><html>
<head>
<meta charset="gb2312">
<title>打字机</title>
</head>
<body>
<script>
var info=new Array("荒烟蔓草的年头,就连分手都很沉默")
var infoNumber=info.length
var whichInfo=-1
function nextInfo()
{
whichInfo=(++whichInfo>(infoNumber-1))?0:whichInfo
setTimeout("showInfo(0)",500)
}
function showInfo(pos)
{
var infoPlat=document.getElementById("infoPlat")
infoPlat.innerHTML=info[whichInfo].substring(0,pos)+"_"
if(++pos>info[whichInfo].length)
{
infoPlat.innerHTML=info[whichInfo].substring(0,pos)
nextInfo()
}
else
setTimeout("showInfo("+pos+")",80)
}
nextInfo()
</script>
<div id="infoPlat"></div>
</body>
</html>
参考下
<!DOCTYPE html><head>
<meta http-equiv="Content-Type" content="text/html charset=utf-8" />
<title>打字机效果</title>
<script>
window.onload = function (){
var text = document.getElementById('text')
var str = '使用JS实现一个打字机字符输出效果使用JS实现一个打字机字符输出效果使用JS实现一个打字机字符输出效果使用JS实现一个打字机字符输出效果'
var arr = []
for(var i=0i<str.lengthi++){
arr.push(str[i])
}
var text1 = ''
var num = 0
var timer = setInterval(function (){
if(num < arr.length){
text1 += arr[num]
text.innerHTML = text1
num++
} else {
clearInterval(timer)
}
},200)
}
</script>
</head>
<body>
<div id='text'></div>
</body>
</html>