The progress bar enables users to see how many web pages are downloaded when they enter your website. This has a very obvious effect-that is, it takes a longer wait time for users, it can effectively make up for the disadvantages of Space slowness (of course, your space is too slow, I suggest you change the space)
Now let me give you two examples.
One is implemented using FLASH (many websites on the Internet, not to mention)
One is implemented using dynamic GIF (you can refer to the official download page of Microsoft, or not to mention it)
Here, we focus on using CSS + JS to achieve this effect.
Let's get started.
First, write an HTML code
<Div id = "loading">
<Strong id = "loadcss"> 33% </strong>
</Div>
Now let's write the CSS code.
# Loading {
Width: 300px;
Background-color: #000;
Border: 2px solid #000;
}
This is what we want the background color of the progress bar to be #000, black, and a border.
J
Next, design multiple loadcss instances.
# Loadcss {
Display: block;/* It is very important to create a block */
Background-color: # 0df;
Text-align: center;
}
Note that the BLOCK here is very important. We use the color # 0df as the color of the progress bar;
Okay. Preview It.
H
But now the entire progress bar is full.
So how can we display the progress?
Here, you can use a clever Method
Slightly modify the HTML code
See the following code:
<Div id = "loading">
<Strong id = "loadcss" style = "width: 33%;"> 33% </strong>
</Div>
Haha, how is it? Now it shows 33%.
But he doesn't move, right? Okay. Now we will use JS to implement it (this JS is not designed by me ...)
<Script language = "JavaScript">
I = 0;
Function load (){
Showload = setInterval ("load ()", 500 );
}
Function setload (){
I + = 5;
If (I> = 100 ){
ClearInterval (showlaod );
}
Document. getElementById ("loadcss"). style. width = I + "% ";
Document. getElementById ("loadcss"). innerHTML = I + "% ";
}
</Script>
Okay. This section of JS mainly contains two functions: load, which is used to enable the progress bar,
The second is setload, which is used to control the position of the progress bar. Set a counter in setload and run steload every 0.5 seconds.
O k. This JS file should be placed in the HEAD and then called in the BODY, that is, <body onload = "LOAD;">
Now, run the web page and try again.