This repository has been archived on 2023-11-13. You can view files and clone it, but cannot push or open issues or pull requests.
cici/js/typeWriter.js
2023-06-16 09:39:28 +08:00

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);
//};