> 웹 프론트엔드 > JS 튜토리얼 > JavaScript는 타이핑 효과를 시뮬레이션합니다.

JavaScript는 타이핑 효과를 시뮬레이션합니다.

高洛峰
풀어 주다: 2016-11-28 14:03:26
원래의
1504명이 탐색했습니다.

JavaScript는 타이핑 효과를 시뮬레이션할 수 있으며 404 페이지로도 사용할 수 있는 매우 창의적인 작은 스크립트입니다. 먼저 인쇄해야 할 문자열을 배열로 미리 저장한 후 setTimeout() 메서드를 사용하여 짧은 시간마다 한 문자씩 출력하면 직렬화하면 입력하는 것과 같은 효과가 나타납니다.


코드

<script type="text/javascript">
<!--
var tl = new Array(
    "I am so sorry, but I can&#39;t find the Page you&#39;ve requested.",
    "It&#39;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&#39;ve tried everything I know to find it.",
    "Nothing helped.",
    "I am really depressed about this.",
    "You see, I&#39;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&#39;t even exist!",
    "Where does that leave me?!",
    "I mean, I don&#39;t even know you.",
    "How should I know what you wanted from me?",
    "You honestly think I can &#39;guess&#39; what someone I don&#39;t even &#39;know&#39; 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&#39;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&#39;s not pretty when a web server cries.",
    "And where do you get off telling me what to show anyway?",
    "I&#39;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&#39;ll crawl off into the trash can and decompose.",
    "I mean, I&#39;m gonna be obsolete in what, two weeks anyway?",
    "What kind of a life is that?",
    "Two effing weeks...",
    "...and then I&#39;ll be replaced by a .01 release, that thinks it&#39;s God&#39;s gift to web servers,",
    "just because it doesn&#39;t have some tiddly little security hole with its HTTP POST implementation,",
    "or something like that.",
    "",
    "I&#39;m really sorry to burden you with all this,",
    "I mean, it&#39;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&#39;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 &#39;my&#39; 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=&#39;&#39;;
    row = Math.max(0,index-7);
    while(row < index)
    {
        contents += tl[row++] + &#39;\r\n&#39;;
    }
    //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>
로그인 후 복사


관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿