When everyone is browsing the website, the text in the active status bar pops up one after another from left to right. Does it make your eyes overwhelmed? Do you also want to make your own web page have the same effect? Now we use JavaScript Program application is used to achieve this effect. Let’s carefully analyze how this dynamic effect is produced.
The idea to achieve this effect is: first assign the text to be presented to a variable, set up a function, and type text on the status bar every once in a while. The text will appear incrementally. When the length of the text is equal to the length of the entire sentence, time, set it to 0, type the text again, and keep looping to get this effect.
Next, let's take a look at the source program.
<script language="JavaScript">
var msg = "Welcome to 5D Multimedia!!";
// The msg variable is to set the text (one sentence) to appear in the status bar
var interval = 120
//Set the interval for how many milliseconds the text length increases by one, here it is 120 milliseconds
var seq=0;
//Represents dynamic text length
functionScroll() {
len = msg.length;
window.status = msg.substring(0, seq+1);
//Add one character to the text
seq++;
//Add one to the length of dynamic text
if ( seq >= len ) {
seq = 0;
window.status = '';
window.setTimeout("Scroll();", interval );
}
//If the length of the dynamic text is the same as the entire sentence, set the length of the dynamic text to 0 and start over.
else
window.setTimeout("Scroll();", interval );
}
Scroll();
</script>
Copy the above source code into the <body></body> tag of the Html file to have the following effects: