自动以HTML格式编写的文本

时间:2013-12-20 20:05:41

标签: javascript html css

我在一些网页上看到文本会自动写在网页上,像终端一样写文本需要几秒钟。 我想知道我们该怎么做?将尝试搜索例如,这样你们就可以很容易地理解,但如果有人看到过这样的东西并且知道该怎么做那么请分享:)

1 个答案:

答案 0 :(得分:0)

纯javascript,google搜索
http://thezillion.wordpress.com/2012/02/27/javascript-typing-effect/

  <html>
    <head>
    <title>Typing Effect - by Zillion</title>
    <script type='text/javascript'>
    var index = 0;
    var text = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque tincidunt, nulla at tempus tristique, nisl leo molestie est, ut vestibulum mauris mauris a odio. Sed at massa vitae ipsum venenatis porta. Integer iaculis pretium tempus. Donec viverra sollicitudin velit non gravida. Phasellus sit amet tortor odio. Vivamus lectus nisl, suscipit porttitor bibendum ut, tristique quis dui. Vestibulum non eros leo. Maecenas tincidunt semper turpis, a tristique purus pretium sit amet. Praesent nec neque tortor.Donec suscipit tristique ante quis molestie. Phasellus ac lacus non felis faucibus dictum vitae ac ipsum. Sed pharetra nulla sodales nulla porta imperdiet. Quisque pretium hendrerit laoreet.';
    // Here you can put in the text you want to make it type.
    function type()
    {
    document.getElementById('screen').innerHTML += text.charAt(index);
    index += 1;
    var t = setTimeout('type()',100);
    // The time taken for each character here is 100ms. You can change it if you want.
    }
    </script>
    </head>
    <body onload='type()'>
    <!-- And here, you create the container in which you display the typed text -->
    <div id='screen'></div>
    </body>
    </html>
另一个

http://jsfiddle.net/AniHouse/x9Ls5/