js 实现打印机效果

Posted on Posted in js

js实现逐字逐句输出

code

<!DOCTYPE html>  
<html>  
    <head>  
        <meta charset="utf-8" />  
        <title>Index</title>  
        <script src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script>  
    </head>  
    <body>  
        <div class="words"></div>  
        <script>  
            var s = '一串文字';  
            var con = $('.words');  
            var index = 0;  
            var length = s.length;  
            var tId = null;  
  
            function start(){  
              con.text('');  
                
              tId=setInterval(function(){  
                con.append(s.charAt(index));  
                if(index++ === length){  
                clearInterval(tId);  
                index = 0;  
                start()  
                }  
              },300);  
            }  
  
            start();      
        </script>  
    </body>  
</html>  

还有一种 : typed.js

官网有说明

» 转载请注明来源:若我若鱼 » js 实现打印机效果

Leave a Reply

Your email address will not be published. Required fields are marked *

ten − five =