feat: 移除了光标 缩短打印的时间

This commit is contained in:
zoujing
2025-08-26 10:54:41 +08:00
parent 0a957310c1
commit 4750bfcf30
2 changed files with 9 additions and 7 deletions

View File

@@ -7,7 +7,7 @@ class TypewriterManager {
// 配置选项
this.options = {
typingSpeed: 50, // 打字速度(毫秒)
cursorText: '<text class="typing-cursor">|</text>', // 光标样式
cursorText: '', // 光标样式
...options
};
@@ -59,7 +59,7 @@ class TypewriterManager {
if (this.isTyping) return;
this.isTyping = true;
this.displayedContent = "";
// 不要在启动时重置displayedContent,而是从当前位置继续
this._typeNextChar();
}
@@ -75,7 +75,7 @@ class TypewriterManager {
this.displayedContent.length + 1
);
const displayContent = this.displayedContent + this.options.cursorText;
const displayContent = this.displayedContent;
// 调用内容更新回调
if (this.onContentUpdate) {
@@ -87,10 +87,12 @@ class TypewriterManager {
this.onCharacterTyped(this.displayedContent);
}
// 继续下一个字符
// 确保最小延迟,避免定时器堆积
const delay = Math.max(this.options.typingSpeed, 30); // 设置最小延迟30ms
this.typewriterTimer = setTimeout(() => {
this._typeNextChar();
}, this.options.typingSpeed);
}, delay);
} else {
// 打字完成,移除光标
if (this.onContentUpdate) {