export class BasicTypeWriter {
private speed;
private currentIndex: number = 1;
private text: string = "";
constructor(public element: HTMLElement, charsPerSecond: number = 20) {
this.speed = 1000 / charsPerSecond;
this.text = element.innerText;
}
write() {
const curText = this.text.slice(0, this.currentIndex);
if (this.currentIndex > this.text.length) {
return;
}
this.element.innerText = curText;
setTimeout(() => {
this.currentIndex++;
this.write();
}, this.speed);
}
setSpeed(charsPerSecond: number) {
this.speed = 1000 / charsPerSecond;
}
}