Very good simulated typing effect. Currently, only plain text, BR tag, and P tag are supported.

Source: Internet
Author: User
Very good simulated typing effect. Currently, only a friend of the plain text, BR tag, and P tag can be used urgently, so I wrote this effect and the Code has some improvements, you can try to modify it to make it more concise and then post it for sharing.

<! Doctype html public "-// W3C // dtd html 4.0 Transitional // EN"> <HTML> <HEAD> <TITLE> New Document </TITLE> <meta name = "Generator "CONTENT =" EditPlus "> <meta name =" Author "CONTENT =" "> <meta name =" Keywords "CONTENT =" "> <meta name =" Description "CONTENT = ""> <style type = "text/css"> body {margin: 0px; font: "" 12px; background-color: #000; color: # fff} </style> <script type = "text/javascript"> var typer = {contai Ner: null, speed: 100, innerHTML: null, curpos: 0, interval1: null, interval2: null, init: function (obj, speed) {typer. container = obj; if (speed) typer. speed = speed; typer. start () ;}, start: function () {typer. innerHTML = clearSpace (typer. container. innerHTML ). toLowerCase (); typer. container. innerHTML = ""; typer. interval1 = setInterval ("typer. type () ", typer. speed) ;}, type: function () {if (t Yper. curpos <typer. innerHTML. length) {if (typer. container. innerHTML. substring (typer. container. innerHTML. length-1 )! = "_") {Typer. container. innerHTML + = "_";} else {var tempStr = ""; if (typer. innerHTML. length> = typer. curpos + 4) {if (typer. innerHTML. substring (typer. curpos, typer. curpos + 4) = "</p>") {tempStr = "</p>"; typer. curpos = typer. curpos + 4;} else if (typer. innerHTML. substring (typer. curpos, typer. curpos + 4) = "") {tempStr = ""; typer. curpos = typer. curpos + 4;} else {if (typer. innerHTML. length> = typer. curpos + 3 & typer. inner HTML. substring (typer. curpos, typer. curpos + 3) = "<p>") {tempStr = "<p>"; typer. curpos = typer. curpos + 3;} else {tempStr = typer. innerHTML. substring (typer. curpos, typer. curpos + 1); typer. curpos ++ ;}} else if (typer. innerHTML. length> = typer. curpos + 3) {if (typer. innerHTML. substring (typer. curpos, typer. curpos + 3) = "<p>") {tempStr = "<p>"; typer. curpos = typer. curpos + 3;} else {tempStr = typer. innerHTML. substring (typer. Curpos, typer. curpos + 1); typer. curpos ++ ;}} else {tempStr = typer. innerHTML. substring (typer. curpos, typer. curpos + 1); typer. curpos ++;} typer. container. innerHTML = typer. container. innerHTML. substring (0, typer. container. innerHTML. length-1) + tempStr;} else {clearInterval (typer. interval1); typer. interval2 = setInterval ("typer. last () ", typer. speed) ;}, last: function () {if (typer. container. innerHTML. subst Ring (typer. container. innerHTML. length-1 )! = "_") Typer. container. innerHTML + = "_"; else typer. container. innerHTML = typer. container. innerHTML. substring (0, typer. container. innerHTML. length-1) ;}} function clearSpace (str) {if (str! = "") {Str = str. replace (/^ \ s */g ,""). replace (/\ s * $/g, "");} return str;} script </HEAD> <BODY onload = "typer. init (document. getElementById ('view') "> <p id =" view "style =" font: ''12px; background-color: #000; color: # fff "> name: Cold mail: cityvoice@hotmail.com Nationality: Hunan <p> hobbies: Play, travel, play interstellar, singing </p> </BODY> </HTML>
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.