手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >JS实现的打字机效果完整实例
JS实现的打字机效果完整实例
摘要:本文实例讲述了JS实现的打字机效果。分享给大家供大家参考,具体如下:JS打字机效果#main{width:80%;height:750px;...

本文实例讲述了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"> <> <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.jb51.net") var msg = "JS打字机效果 ,原理很简单:每次多获取一个待打出的字符串的值,输出,覆盖原来输出的内容即可"; function getMsg(){ return msg; } typeWriter.msg = getMsg(msg); typeWriter.type(); } </script> </head> <body> <div id = "main"> </div> </body> </html>

希望本文所述对大家JavaScript程序设计有所帮助。

【JS实现的打字机效果完整实例】相关文章:

JS+CSS实现仿触屏手机拨号盘界面及功能模拟完整实例

JavaScript实现Iterator模式实例分析

卡拉 OK 字幕效果

JavaScript实现简单的数字倒计时

JS实现浏览器菜单命令

javascript实现淡蓝色的鼠标拖动选择框实例

jQuery实现首页图片淡入淡出效果的方法

js实现顶部可折叠的菜单工具栏效果实例

JS+DIV实现鼠标划过切换层效果的方法

JavaScript实现鼠标拖动效果的方法

精品推荐
分类导航