HTML5+CSS3 Web page loading progress bar implementation, download progress bar

Source: Internet
Author: User
Today to bring a more dazzling progress bar, the progress bar in a time-consuming operation to give users a better experience, will not let the user feel blindly waiting, for no progress bar long wait, the user will be the task of the crash, do not hesitate to switch off the application; commonly used for download tasks, delete a large number of tasks, page loading, etc. If you use HTML5 for mobile phone layout, it can also be used in the phone.

1. HTML Structure:

<p id= "LoadBar01" class= "Loadbar" >         <p>              <span class= "percent" >                 <i></i>              </span>         </p>         <span class= "Percentnum" >0%</span>     </p>

Under Simple analysis:

P.loadbar represents the entire progress bar

P.loadbar p Sets the Fillet table box, P.loadbar p span as the progress (dynamic change width), P.loadbar p span I fills the background color for progress (that is, width=100%)

HTML structure, we can design their own, as long as reasonable, there is no problem ~

2. CSS:

Body {font-family:thoma, Microsoft Yahei, ' Lato ', Calibri, Arial, Sans-serif;             } #content {margin:120px auto;         width:80%;             }. loadbar {width:600px;             height:30px;             BORDER:3PX solid #212121;             border-radius:20px;         position:relative;             }. Loadbar p {width:100%;             height:100%;             Position:absolute;             top:0;         left:0;             }. Loadbar p span,. Loadbar p I {box-shadow:inset 0-2px 6px rgba (0, 0, 0,. 4);             width:0%;             Display:block;             height:100%;             Position:absolute;             top:0;             left:0;         border-radius:20px;             }. Loadbar p i {width:100%;             -webkit-animation:move. 8s linear infinite; backgRound:-webkit-linear-gradient (left Top, #7ed047 0, #7ed047 25%, #4ea018 25%, #4ea018 50%, #7ed047 50%, #7ed047 75%, #4ea             018 75%, #4ea018 100%);         background-size:40px 40px;             }. Loadbar. percentnum {position:absolute;             top:100%;             right:10%;             PADDING:1PX 15px;             border-bottom-left-radius:16px;             border-bottom-right-radius:16px;             border:1px solid #222;             Background-color: #222;           Color: #fff;             } @-webkit-keyframes Move {0% {background-position:0 0;             } 100% {background-position:40px 0; }         }

At this point the effect is:

The overall layout is the use of position relative and absolute~

The more difficult part is the implementation of the gradient bar:

We use

A, gradient from top left to bottom right

b, the color is: 0-25% for #7ed047, 25%-50% for #4ea018, 50%-75% for #7ed047, 75%-100% for #4ea018

C, the size of the background is 40px 40px This setting exceeds the height of the line, the larger the width of the provisions wider

Analysis Diagram:

The principle of setting is that, while the background width can be set larger, the width of the article is larger;

3, Set JS, create Loadbar Object

function Loadingbar (ID)         {             This.loadbar = $ ("#" + ID);             This.percentele = $ (". Percent", this.loadbar);             This.percentnumele = $ (". Percentnum", This.loadbar);             This.max = +;             this.currentprogress = 0;         }         Loadingbar.prototype = {             Constructor:loadingbar,             setmax:function (maxval)             {                 This.max = maxval;             } ,             Setprogress:function (val)             {                 if (val >= this.max)                 {                     val = This.max;                 }                 This.currentprogress = parseint ((val/this.max) * +) + "%";                 This.percentEle.width (this.currentprogress);                 This.percentNumEle.text (this.currentprogress);                 }         };

We created a Loadbar object, and exposed two methods, one setting the maximum progress, one setting the current progress, such as the download file maximum progress is the file size, the current progress is the downloaded file size.

4. Testing

Finally we test our code:

$ (function ()       {             var loadbar = new Loadingbar ("LoadBar01");           var max = +;           Loadbar.setmax (max);           var i = 0;           var time = setinterval (function ()           {               loadbar.setprogress (i);               if (i = = max)               {                   clearinterval (time);                   return;               }               i + = ten;           }, +);       });

SOURCE Click to download: Demo

The above is the whole content of this article, I hope that everyone's learning has helped, but also hope that we support topic.alibabacloud.com.

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.