[JS]文字逐字打出

好久不更新了 [JS]文字逐字打出 代码如下 <!DOCTYPE html> <html>     <head>         <meta charset="UTF-8">         <title>Title</title>     &lt...

好久不更新了

[JS]文字逐字打出

代码如下

<!DOCTYPE html>
<html>

    <head>
        <meta charset="UTF-8">
        <title>Title</title>
    </head>

    <body>
        <div id="content"></div>
    </body>

    <script>
        window.onload = function() {
            let word = '我是一个个的文字,慢慢的被打出 ';
            let n = 0;
            let t = setInterval(function() {
                n++;
                console.log('n:' + n + ",word.length:" + word.length);
                if(n > word.length) clearInterval(t);
                document.getElementById('content').innerText = word.substring(0, n);
            }, 100);
        }
    </script>

</html>


  • 发表于 2021-04-03 11:23
  • 阅读 ( 317 )
  • 分类:互联网

0 条评论

请先 登录 后评论
辰溪
辰溪

681 篇文章

你可能感兴趣的文章

相关问题