feat: 移除了光标 缩短打印的时间
This commit is contained in:
@@ -526,8 +526,8 @@ const initTypewriterManager = () => {
|
||||
}
|
||||
|
||||
typewriterManager = new TypewriterManager({
|
||||
typingSpeed: 50,
|
||||
cursorText: '<text class="typing-cursor">|</text>',
|
||||
typingSpeed: 30,
|
||||
cursorText: '',
|
||||
});
|
||||
|
||||
// 设置回调函数
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user