JS實(shí)現(xiàn)的打字機(jī)效果完整實(shí)例
本文實(shí)例講述了JS實(shí)現(xiàn)的打字機(jī)效果。分享給大家供大家參考,具體如下:
<!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打字機(jī)效果</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,//打字時(shí)間(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://chabaoo.cn") var msg = "JS打字機(jī)效果 ,原理很簡(jiǎn)單:每次多獲取一個(gè)待打出的字符串的值,輸出,覆蓋原來輸出的內(nèi)容即可"; function getMsg(){ return msg; } typeWriter.msg = getMsg(msg); typeWriter.type(); } </script> </head> <body> <div id = "main"> </div> </body> </html>
更多關(guān)于JavaScript相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《JavaScript切換特效與技巧總結(jié)》、《JavaScript查找算法技巧總結(jié)》、《JavaScript動(dòng)畫特效與技巧匯總》、《JavaScript錯(cuò)誤與調(diào)試技巧總結(jié)》、《JavaScript數(shù)據(jù)結(jié)構(gòu)與算法技巧總結(jié)》、《JavaScript遍歷算法與技巧總結(jié)》及《JavaScript數(shù)學(xué)運(yùn)算用法總結(jié)》
希望本文所述對(duì)大家JavaScript程序設(shè)計(jì)有所幫助。
相關(guān)文章
用javascript實(shí)現(xiàn)記錄來賓姓名的代碼
用javascript實(shí)現(xiàn)記錄來賓姓名的代碼...2007-03-03使用Bootstrap typeahead插件實(shí)現(xiàn)搜索框自動(dòng)補(bǔ)全的方法
這篇文章主要介紹了使用Bootstrap typeahead插件實(shí)現(xiàn)搜索框自動(dòng)補(bǔ)全的方法的相關(guān)資料,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-07-07JavaScript SweetAlert插件實(shí)現(xiàn)超酷消息警告框
SweetAlert是一款使用純js制作的消息警告框插件.這篇文章主要介紹了JavaScript SweetAlert插件實(shí)現(xiàn)超酷消息警告框的相關(guān)資料,需要的朋友可以參考下2016-01-01原生JS+HTML5實(shí)現(xiàn)的可調(diào)節(jié)寫字板功能示例
這篇文章主要介紹了原生JS+HTML5實(shí)現(xiàn)的可調(diào)節(jié)寫字板功能,涉及javascript結(jié)合HTML5屬性動(dòng)態(tài)操作頁(yè)面元素實(shí)現(xiàn)繪圖功能相關(guān)技巧,需要的朋友可以參考下2018-08-08微信小程序一周時(shí)間表功能實(shí)現(xiàn)
這篇文章主要介紹了微信小程序一周時(shí)間表功能實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-10-10小程序?qū)崿F(xiàn)頁(yè)面多級(jí)來回切換的示例代碼
這篇文章主要為大家詳細(xì)介紹了小程序如何頁(yè)面多級(jí)來回切換支持滑動(dòng)和點(diǎn)擊操作,文中的實(shí)現(xiàn)步驟講解詳細(xì),快跟隨小編一起動(dòng)手嘗試一下吧2022-07-07