This chapter mainly introduces the typing effect that can often be seen when browsing the web. The code in this section mainly uses the onMousedown event and the event.button attribute. The main functions and usage are as follows.
• The setTimeout method, when executed, executes the expression once and only once after delaying the specified time after loading.
• The charAt method returns a character value that is located at the specified index position. The first character in the string has index 0, the second has index 1, and so on. Index values outside the valid range return an empty string.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
After running the program, a prompt message appears on the page, and then characters appear one by one. After characters appear one by one in this way, wait until all printing is completed to stop printing.
Source program interpretation
(1) The program first creates a layer with an ID of ttl0 for easy calling later. This layer is used to display printed text.
(2) The program adds an onLoad event to the element. When the entire page is loaded, the event is triggered and the init() event handling function is called to process the event.
(3) In the function txtTyper(), use the charAt method to get a certain character in the string. Use the if conditional statement to determine whether the character meets the end. Printed on the page after the conditions are met.
(4) In the if statement, you can also use any legal Javascript statement to complete more complex operations.
The above is the detailed content of Introducing a special effect example using javascript to achieve text typing effect. For more information, please follow other related articles on the PHP Chinese website!