最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

JavaScript模拟打字效果

来源:动视网 责编:小采 时间:2020-11-27 20:30:35
文档

JavaScript模拟打字效果

JavaScript模拟打字效果:JavaScript可以模拟打字效果,很有创意的一个小脚本,可以用作404页面,当然也可以用在很多地方。先把需要打印的字符串预先保存到一个数组当中,然后利用setTimeout()方法每个一小段时间输出一个字符,连串起来就像打字一样的效果。Code<scri
推荐度:
导读JavaScript模拟打字效果:JavaScript可以模拟打字效果,很有创意的一个小脚本,可以用作404页面,当然也可以用在很多地方。先把需要打印的字符串预先保存到一个数组当中,然后利用setTimeout()方法每个一小段时间输出一个字符,连串起来就像打字一样的效果。Code<scri


JavaScript可以模拟打字效果,很有创意的一个小脚本,可以用作404页面,当然也可以用在很多地方。先把需要打印的字符串预先保存到一个数组当中,然后利用setTimeout()方法每个一小段时间输出一个字符,连串起来就像打字一样的效果。

Code

<script type="text/javascript">
<!--
var tl = new Array(
 "I am so sorry, but I can't find the Page you've requested.",
 "It's possible that you entered the address incorrectly.",
 "If you did enter the address correctly, then it must be my fault.",
 "I am really, really sorry, but I've tried everything I know to find it.",
 "Nothing helped.",
 "I am really depressed about this.",
 "You see, I'm just a web server...",
 "...here I am, brain the size of the universe, trying to serve you a simple web page...",
 "And then it doesn't even exist!",
 "Where does that leave me?!",
 "I mean, I don't even know you.",
 "How should I know what you wanted from me?",
 "You honestly think I can 'guess' what someone I don't even 'know' wants to find here?",
 "",
 "Maybe I should introduce myself... my name is Marvin.",
 "But then again, what is the use of intruducing myself?",
 "You can't tell me your name, because you are in some far off place, sitting in front of your computer.",
 "And that makes me feel lonely.",
 "Do you know what that is like?",
 "",
 "...sigh...",
 "",
 "Man, I am so depressed I could just cry.",
 "And then where would we be, I ask you?",
 "It's not pretty when a web server cries.",
 "And where do you get off telling me what to show anyway?",
 "I'm just a web server...",
 "...and possibly a manic depressive one at that...",
 "So why does that give you the right to tell me what to do?",
 "Huh?",
 "",
 "I am so depressed...",
 "I think I'll crawl off into the trash can and decompose.",
 "I mean, I'm gonna be obsolete in what, two weeks anyway?",
 "What kind of a life is that?",
 "Two effing weeks...",
 "...and then I'll be replaced by a .01 release, that thinks it's God's gift to web servers,",
 "just because it doesn't have some tiddly little security hole with its HTTP POST implementation,",
 "or something like that.",
 "",
 "I'm really sorry to burden you with all this,",
 "I mean, it's not your job to listen to my problems,",
 "and I guess it is my job to go and fetch web pages for you.",
 "But I couldn't get this one.",
 "I am so sorry.",
 "Believe me!",
 "",
 "Maybe I could interest you in another page?",
 "There are a lot out there that are pretty neat, they say,",
 "although none of them were put on 'my' server, of course.",
 "Figures, huh?",
 "That makes me depressed too, since I have to serve them, all day and all night long.",
 "Two weeks of information overload, and then *pffftt*, consigned to the trash.",
 "Again I ask you, what kind of a life is that?",
 "",
 "Now, please let me sulk alone.",
 "",
 "",
 "",
 "",
 "I am so depressed.",
 "",
 "",
 "",
 "",
 "",
 "",
 "",
 "<connection terminated>"
);
var speed = 50;
var index = 0; 
text_pos = 0;
var str_length = tl[0].length;
var contents, row;
 
function type_text()
{
 contents='';
 row = Math.max(0,index-7);
 while(row < index)
 {
 contents += tl[row++] + '\r\n';
 }
 //document.forms[0].elements[0].value = contents + tl[index].substring(0,text_pos) + "_";
 document.getElementById("typearea").value = contents + tl[index].substring(0,text_pos) + "_";
 if(text_pos++==str_length)
 {
 text_pos=0;
 index++;
 if(index!=tl.length)
 {
 str_length=tl[index].length;
 setTimeout("type_text()",1500);
 }
 } 
 else
 setTimeout("type_text()",speed);
}
//-->
</script> 
 
<form> 
 <textarea id="typearea" rows="20" cols="100" style="font-family:Arial; font-size:14px; "></textarea> 
</form> 
<script type="text/javascript">type_text();</script>

文档

JavaScript模拟打字效果

JavaScript模拟打字效果:JavaScript可以模拟打字效果,很有创意的一个小脚本,可以用作404页面,当然也可以用在很多地方。先把需要打印的字符串预先保存到一个数组当中,然后利用setTimeout()方法每个一小段时间输出一个字符,连串起来就像打字一样的效果。Code<scri
推荐度:
标签: 打字 js 效果
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top