JS實現的打字機效果完整執行個體,js打字機執行個體

來源:互聯網
上載者:User

JS實現的打字機效果完整執行個體,js打字機執行個體

本文執行個體講述了JS實現的打字機效果。分享給大家供大家參考,具體如下:

<!DOCTYPE html><html lang="en">  <head>    <meta charset="utf-8">    <!-- Always force latest IE rendering engine (even in intranet) & Chrome Frame    Remove this if you use the .htaccess -->    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">    <title>JS打字機效果</title>    <meta name="description" content="">    <meta name="author" content="Administrator">    <meta name="viewport" content="width=device-width; initial-scale=1.0">    <!-- Replace favicon.ico & apple-touch-icon.png in the root of your domain and delete these references -->  <style type = "text/css">   #main {    width: 80%;    height: 750px;    margin: auto;    padding: 10px;    background: #cfe1ca;    border: 10px outset #f9c6aa;    line-height: 30px;    color: #9f3c61;    font-size: 18px;   }   p {    text-indent: 30px;   }  </style>  <script type = "text/javascript">   var typeWriter = {    msg: function(msg){     return msg;    },    len: function(){     return this.msg.length;    },    seq: 0,    speed: 150,//打字時間(ms)    type: function(){     var _this = this;     document.getElementById("main").innerHTML = _this.msg.substring(0, _this.seq);     if (_this.seq == _this.len()) {      _this.seq = 0;       clearTimeout(t);     }     else {      _this.seq++;      var t = setTimeout(function(){_this.type()}, this.speed);     }    }   }   window.onload = function(){    alert("welcome to http://www.bkjia.com")    var msg = "JS打字機效果 ,原理很簡單:每次多擷取一個待打出的字串的值,輸出,覆蓋原來輸出的內容即可";    function getMsg(){     return msg;    }    typeWriter.msg = getMsg(msg);    typeWriter.type();   }  </script> </head> <body>  <div id = "main"> </div> </body></html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.