37 lines
682 B
JavaScript
37 lines
682 B
JavaScript
|
|
let i = 0;
|
|
let text1 = "你好啊,小扈同学,很高兴认识你!";
|
|
let text2 = "愿我们每一天都是值得纪念的,也是值得怀念的。"
|
|
let speed = 100;
|
|
|
|
function typeWriter(text, para){
|
|
if(ok == 2){
|
|
clearInterval(typeInterval);
|
|
}
|
|
if(i < text.length){
|
|
document.getElementById(para).innerHTML += text.charAt(i);
|
|
i++;
|
|
speed = Math.random() * 50 + 100;
|
|
}
|
|
else{
|
|
if(ok == 0){
|
|
i = 0;
|
|
}
|
|
ok += 1;
|
|
}
|
|
}
|
|
|
|
var typeInterval;
|
|
|
|
//window.onload = function() {
|
|
// window.onload = function(){};
|
|
typeInterval = setInterval(function(){
|
|
if(ok == 0){
|
|
typeWriter(text1, "txt1");
|
|
}
|
|
else if(ok == 1){
|
|
typeWriter(text2, "txt2");
|
|
}
|
|
}, 300);
|
|
//};
|