JavaScript Progress bar Implementation code (not supported by similar browsers like Firefox) _javascript tips

Source: Internet
Author: User
Tags setinterval
Copy Code code as follows:

[Code]
<script type= "Text/javascript" >
var loading = {
Element:null,
count:0,
id:0,
Createloading:function (parent, width, height) {//To build the perimeter of the progress bar box
Loading.element = document.createelement ("div");
Loading.element.id = "Loading";
Loading.element.className = "Loading";
Loading.element.style.height = height;
Loading.element.style.backgroundColor = "#ffffff";
Loading.element.style.border = "1px solid #333333";
Loading.element.style.width = width;
Parent.appendchild (loading.element);
Loading.interval ();
},
Addsubdiv:function () {///setinterval Add the div tag inside the perimeter box to achieve the progress effect
If the width of the perimeter box is reached, the progress is displayed again
if ((Loading.count + 1) * 2 >= parseint (loading.element.style.width)) {
Loading.count = 0;
Clearinterval (loading.id);
Loading.element.innerHTML = "";
Loading.interval ();
}
else {
var elem = document.createelement ("div");
Elem.classname= sub-loading;
Elem.style.backgroundColor = "#f00";
Elem.style.width = "2px";
Elem.style.height = Loading.element.style.height;
elem.style.display= "inline";
Loading.element.appendChild (Elem);
loading.count++;
}
},
Interval:function () {//called repeatedly
Loading.id = SetInterval (Loading.addsubdiv, 30);
}
}
onload = function () {
Loading.createloading (document.getElementById ("parent"), "402px", "15px");
}
</script>

[/code]
To run the demo code:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" > <ptml><pead><title>javascript Data Access test</title> <meta http-equiv=content-type content= "text/html; charset=gb2312 "> <script type=text/javascript> var loading = {Element:null, count:0, id:0, Createloadin G:function (parent, width, height) {loading.element = document.createelement ("div"); Loading.element.id = "Loading"; Loading.element.className = "Loading"; Loading.element.style.height = height; Loading.element.style.backgroundColor = "#ffffff"; Loading.element.style.border = "1px solid #333333"; Loading.element.style.width = width; Parent.appendchild (loading.element); Code from Jb51.net loading.interval (); }, Addsubdiv:function () {if (Loading.count + 1) * 2 >= parseint (loading.element.style.width)) {loading.count = 0; Clearinterval (loading.id); Loading.element.innerHTML = ""; Loading.interval (); else {var elem = document.createelement("div"); Elem.classname= ' sub-loading '; Elem.style.backgroundColor = "#f00"; Elem.style.width = "2px"; Elem.style.height = Loading.element.style.height; elem.style.display= "inline"; Loading.element.appendChild (Elem); loading.count++; }, Interval:function () {loading.id = SetInterval (Loading.addsubdiv, 30); The onload = function () {loading.createloading (document.getElementById ("parent"), "402px", "15px"); } </SCRIPT> <style>.sub-loading {display:inline} </STYLE> <meta content= "MSHTML 6.00.60 00.16850 "name=generator></pead> <body class=body> <div id=parent></div></body> </HTML>
[Ctrl + A All SELECT Note: If the need to introduce external JS need to refresh to perform]
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.