JavaScript implements automatic output text (typing effect) _javascript tips

Source: Internet
Author: User
Tags time interval

The main use of settimeout (), recursion and string.substring ();

The effect is like having a typist typing.

<!doctype html>  

Method II: JavaScript to achieve typing effect of typewriting computer

<span id= "Demo" ></span>
<script defer>
var text= "javascript-implemented typing effect"  //Predefined text
var  delay=200             //text occurrence time interval
var i=0                //initialization variable i
function Scrollit () {
//Set the text within the object with the demo ID to start with 0 from the variable text to I Between the text plus "_"
Demo.innertext=text.slice (0,i++) + "_"  
if (i>text.length) {       //When I is greater than text length
  i=0              //Reset I to 0, so that the text again from the first text appear
//delay to perform the scrollit () function, delay*10 is to allow the display of the full text of a little longer
  settimeout ("Scrollit ()", delay*10) 
}
  //Otherwise execute scrollit () function
else settimeout ("Scrollit ()", delay)
after delay milliseconds Scrollit ()//Call Scrollit () function
</script>

Method Three:

 

Related Article

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.