打字机效果,即博客顶部效果

125 阅读1分钟
  /**
        * 模块名:
        * 代码描述: 文字循环
        * 作者:lizibin
        * 创建时间:2023/01/02 09:56:46
        */
        const circulateText = () => {
            // 随机选择textArr的一个值
            let random = Math.floor(Math.random() * (state.top_text.length));
            let nowText = state.top_text[random];
            let i = 0;
            textTimer = setInterval(function () {
                if (state.activeText.length < nowText.length) {
                    state.activeText += nowText[i++];
                } else {
                    state.activeText = ''
                    clearInterval(textTimer)
                    circulateText()
                }
            }, 500)
        }