Html + css + jquery implements a simple progress bar instance, cssjquery

Source: Internet
Author: User

Html + css + jquery implements a simple progress bar instance, cssjquery

<! DOCTYPE html>
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> jquery implementation progress bar </title>
<Style type = "text/css">
Body {
Padding: 30px;
Margin-left: pixel PX;
Margin-top: 200px;
Width: 350px;
Border: 1px solid #98AFB7;
}
. ProgressBar {
Width: 280px;
Height: 20px;
Border: 1px solid #98AFB7;
Border-radius: 8px;
Background: # e1dfdf;
}
Input {
Margin-bottom: 15px;
}
Span {
Position: relative;
Top:-20px;
Left: 290px;
}
# Bar {
Width: 0px;
Height: 20px;
Border-radius: 7px;
Background: # 5EC4EA;
}
</Style>

// Introduce the Jquery File

<Script src = "Jquerys/jquery. js"> </script>
<Script type = "text/javascript">
Function progressBar (){
$ ("# Bar" ).css ("width", "0px ");
Var speed = 20; // speed of the progress bar

Bar = setInterval (function (){
NowWidth = parseInt ($ ("# bar"). width ());
If (nowWidth <= 279 ){
Var barWidth = (nowWidth + 1 );
$ ("# Bar" ).css ("width", barWidth + "px ");
Var totla = parseInt ($ (". progressBar"). width ())
Var ss = barWidth/totla * 100;

$ ("# Span_s"). text (ss );
Var index = $ ("# span_s"). text (). indexOf (".");
If (index! =-1 ){
Var context = $ ("# span_s"). text (). substring (0, index );
$ ("# Span_s"). text (context );
}
Else {
$ ("# Span_s"). text (ss );
If (parseInt ($ ("# span_s"). text () = 100 ){
Alert ('complete ');
}
}
} Else {
ClearInterval (bar );
}
}, Speed );
}

</Script>


</Head>
<Body>
<Input type = "button" value = "start" onclick = "progressBar ()"/>
<Div class = "progressBar"> <div id = "bar"> </div> <span id = "span_s"> 0 </span> <span> % </span>
</Body>
</Html>

 

This progress bar is very simple. First, a div inside the html is embedded with a div, and then you can write the desired style. The implementation of the special effect is very simple, writing an anonymous function in a timer is also easy to implement. Here I am executing an anonymous function in 20 milliseconds, and the code in it is to add one pixel at a time, you can also add pixels by percentage here. Another method is introduced. You can also use animations to achieve the progress bar effect ...... If you are interested, try it.

 

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.