Example of JavaScript typing

Source: Internet
Author: User

There is a jQuery plug-in Typed. js on the Internet that can simulate character-by-character input. This post uses Js + css to achieve this effect.


Sentence to be output:

<P id = "my_string" hidden> HelloJavaScript. </p>
The property of the above element is Den.

JavaScript:

<Script>
Letcursor = "<span >|</span> ";
Letmy_str = my_string.innerHTML;
   
Function typeIt (){
Letcounter = 0;
My_string.innerHTML = cursor;
My_string.removeAttribute ("hidden ");
Let I = setInterval (function (){
My_string.innerHTML = my_str.substr (0, counter) + cursor;
Counter ++;
If (counter === my_str.length + 1 ){
ClearInterval (I );
                            }
},200 );
    }
 
TypeIt ();
</Script>
Css:

<Style>
@ Keyframes blink {
From, {
Color: transparent;
        }
50% {
Color: black;
        }
    }
 
# My_string span {
Animation: blink 1 s step-end infinite;
}
</Style>
Share the post "using JavaScript for typing"

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.