js 实现 文字打印效果

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>打印效果 测试</title>
    <style>
        body{
            background: #000;
        }
        #demo{
            font-family: helvetica;
            text-transform: uppercase;
            text-align: center;
            color: #fefefe;
            font-size: 200px;
            text-shadow: #e7e7e7 3px 5px 0, #999 4px 6px 3px, #ccc 8px 11px 10px;  
        }
    </style>
</head>
<body>
    <div id="demo">
        
    </div>
    <script>
        var  str = "for example,再有几天都该七夕节了,你为她准备了什么礼物?",
           i =0,
           cal;
        function demoStr(){
            if(i < str.length){
                cal = str.substring(0, i++) + "_";
                document.getElementById("demo").innerHTML = cal;
                setTimeout(demoStr,500);
            }else{
                document.getElementById("demo").innerHTML = str;  //相当于清除下划线以及计时器效果
            }
        } 
        demoStr();
    </script>
</body>
</html>

 

posted @ 2017-08-18 15:19  我要成为酷酷的人  阅读(1459)  评论(0编辑  收藏  举报