Javascript progress bar

Source: Internet
Author: User

This article will describe how to use JavaScript to create two types of progress bars and package the core code. Put it in percent. js

/**
* Draw a simple percentage progress bar
* ID of the Barid progress bar Span
* Percentage of fpercent completion
* Strcaption title
* Iheight height
* Minimum iunit
* Bgcolor background color
* Border border Style
* Cursor Style
*/
Function simplepercent (Barid, fpercent, strcaption, iheight, iunit, bgcolor, border, cursor ){
VaR pbar = Document. All (Barid );
If (pbar)
{
Pbar. Title = strcaption + fpercent + "% ";
Pbar. innerhtml = "";
If (bgcolor ){
Pbar. style. backgroundcolor = bgcolor;
}
If (border = NULL ){
Border = "1px solid #000000 ";
}
Pbar. style. Border = border;
If (cursor = NULL ){
Cursor = "default ";
}
Pbar. style. cursor = cursor;

If (iheight = NULL | iheight <1 ){
Iheight = 1;
}
Pbar. style. Height = iheight + "PX ";
If (iunit = NULL | iunit <1 ){
Iunit = 1;
}
Pbar. style. width = (iunit * 100) + "PX ";

Pbar. insertadjacenthtml ("beforeend", "<span style = 'width:" + (iunit * fpercent) + "PX; Height:" + iheight + "PX; Background-color: # 0000ff; '> </span> ");

}
}
Instance:
<HTML>
<Head>
<Title> draw a simple percentage progress bar </title>
</Head>
<Body>

<Span id = "_ percentbar"> </span>

<Script language = "JavaScript" type = "text/JavaScript" src = "percent. js">

</SCRIPT>
<Script language = "JavaScript" type = "text/JavaScript">
Simplepercent ("_ percentbar", 77, "installation progress", 10, 5 );
</SCRIPT>
</Body>
</Html>

/**
* Percentage progress
*/
VaR _ hex = array ("00", "01", "02", "03", "04", "05", "06", "07 ", "08", "09", "0a", "0b", "0C", "0d", "0e", "0f", "10", "11 ", "12", "13", "14", "15", "16", "17", "18", "19", "1A", "1B ", "1C", "1D", "1E", "1f", "20", "21", "22", "23", "24", "25 ", "26", "27", "28", "29", "2a", "2B", "2C", "2D", "2e", "2f ", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39 ", "3A", "3B", "3C", "3D", "3e", "3f", "40", "41", "42", "43 ", "44", "45", "46", "47", "48", "49", "4A", "4B", "4C", "4D ", "4E", "4f", "50", "51", "52", "53", "54", "55", "56", "57 ", "58", "59", "5A", "5B", "5c", "5d", "5E", "5f", "60", "61 ", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6B ", "6C", "6D", "6e", "6f", "70", "71", "72", "73", "74", "75 ", "76", "77", "78", "79", "7A", "7b", "7C", "7D", "7E", "7f ", "80", "81", "82", "83", "84", "85", "86", "87", "88", "89 ", "8a", "8b", "8C", "8d", "8e", "8f", "90", "91", "92", "93 ", "94", "95", "96", "97", "98", "99", "9A", "9B", "9C", "9d ", "9e", "9f", "A0", "A1", "A2", "A3", "A4", "A5", "A6", "A7 ", "A8", "A9", "AA", "AB", "AC", "ad", "AE", "af", "B0", "B1 ", "B2", "B3", "B4", "B5", "B6", "B7", "B8", "B9", "ba", "BB ", "BC", "BD", "be", "BF", "C0", "C1", "C2", "C3", "C4", "C5 ", "C6", "C7", "C8", "C9", "ca", "CB", "cc", "cd", "CE", "CF ", "D0", "d1", "D2", "D3", "D4", "D5", "D6", "D7", "D8", "D9 ", "Da", "DB", "DC", "DD", "de", "DF", "E0", "E1", "E2", "E3 ", "E4", "E5", "E6", "E7", "E8", "E9", "EA", "Eb", "EC", "Ed ", "ee", "Ef", "F0", "f1", "F2", "F3", "F4", "F5", "F6", "F7 ", "F8", "F9", "Fa", "FB", "FC", "FD", "Fe", "FF ");

/**
* Progress bar for drawing the gradient percentage
* ID of the Barid progress bar Span
* Percentage of fpercent completion
* Strcaption title
* Bdouble 100 or 200 unit
* Minimum iunit
* Bgcolor background color
* Border border Style
* Cursor Style
*/
Function paintpercent (Barid, fpercent, strcaption, bdouble, iheight, iunit, bgcolor, border, cursor ){
VaR pbar = Document. All (Barid );
If (pbar)
{
Pbar. Title = strcaption + fpercent + "% ";
Pbar. innerhtml = "";
If (bgcolor ){
Pbar. style. backgroundcolor = bgcolor;
}
If (border = NULL ){
Border = "1px solid #000000 ";
}
Pbar. style. Border = border;
If (cursor = NULL ){
Cursor = "default ";
}
Pbar. style. cursor = cursor;

If (iheight = NULL | iheight <1 ){
Iheight = 1;
}
Pbar. style. Height = iheight + "PX ";
If (iunit = NULL | iunit <1 ){
Iunit = 1;
}
If (bdouble ){
Bdouble = 2;
}
Else {
Bdouble = 1;
}

Pbar. style. width = (iunit * bdouble * 100) + "PX ";
Pbar. style. whitespace = "nowrap ";

For (VAR idx = 0; idx <bdouble * 100; idx ++ ){
If (idx <fpercent * bdouble ){
Pbar. insertadjacenthtml ("beforeend", "<span style = 'width:" + iunit + "PX; Height:" + iheight + "PX; Background-color: #00 "+ _ hex [256-idx] +" ff; '> </span> ");
} Else {
Pbar. insertadjacenthtml ("beforeend", "<span style = 'width:" + iunit + "PX; Height:" + iheight + "PX"> </span> ");
}
}
}
}
Instance:
<HTML>
<Head>
<Title> progress bar for drawing the gradient percentage </title>
</Head>
<Body>

<Table>
<Tr>
<TD>
<Span id = "_ percentbar"> </span>
</TD>
</Tr>
</Table>

<Script language = "JavaScript" type = "text/JavaScript" src = "percent. js">

</SCRIPT>
<Script language = "JavaScript" type = "text/JavaScript">
Paintpercent ("_ percentbar", 89, "installation progress", true, 18 );
</SCRIPT>
</Body>
</Html>

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.