Effect of progress bars implemented with CSS + JS

Source: Internet
Author: User

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.

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.