javascript实现进度条

<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.0   Transitional//EN">  
  <HTML>  
  <HEAD>  
  <TITLE>   New   Document   </TITLE>  
  <META   NAME="Generator"   CONTENT="EditPlus">  
  <META   NAME="Author"   CONTENT="">  
  <META   NAME="Keywords"   CONTENT="">  
  <META   NAME="Description"   CONTENT="">  
  </HEAD>  
   
  <BODY>  
  <SCRIPT   LANGUAGE="JavaScript">  
  <!--  
    function   TProgressBar(idstr,x,y,w,h,c,bgc,max,min)  
    {  
        this.idstr=idstr||"mypb";  
        this.obj=null;  
        this.min=min||0;  
        this.max=max||100;  
        this.x=x||100;  
        this.y=y||100;  
        this.width=w||204;  
        this.height=h||24;  
        this.color=c||"#FF6600";  
        this.bgcolor=bgc||"#E1E1E1";  
        this.pos=0;  
        this.percent=0;  
        this.Create=TProgressBar_Create;  
        this.Update=TProgressBar_Update;  
        this.Reposition=TProgressBar_Reposition;  
    }  
    function   TProgressBar_Update()  
    {  
          this.percent=Math.floor(this.pos/this.max*100);  
  if(this.percent>=100)  
  {  
      this.percent=100;  
      this.obj.width=this.width-4;  
  }  
  else  
  {  
              this.obj.width=Math.floor(this.pos/this.max*(this.width-4));  
  }  
  this.counter.innerHTML=String(this.percent)+"%";      
           
    }  
    function   TProgressBar_Create()  
    {  
          var   str="";  
  str+='<div   id="'+this.idstr+'_border"   style="position:absolute;   left:'+this.x+'px;   top:'+this.y+'px;   width:'+this.width+'px;   height:'+this.height+'px;   z-index:1;   background-color:   #000000;">';  
          str+='<div   id="'+this.idstr+'_bg"   style="position:absolute;   left:1px;top:1px;width:'+(this.width-2)+'px;   height:'+(this.height-2)+'px;   z-index:2;   background-color:   '+this.bgcolor+';">';  
                    str+='<div   id="'+this.idstr+'_main"   style="position:absolute;   left:1px;   top:1px;   width:1px;   height:'+(this.height-4)+'px;   z-index:3;   background-color:   '+this.color+';font-size:1px"></div>';  
                    str+='<div   id="'+this.idstr+'_counter"   style="position:absolute;width:10px;height:'+(this.height-4)+'px;left:'+(this.width/2-10)+'px;top:1px;z-index:3">0%</div>';  
  str+='</div></div>';  
  document.write(str);  
  this.obj=document.all[this.idstr+"_main"].style;  
  this.counter=document.all[this.idstr+"_counter"];  
    }  
    function   TProgressBar_Reposition()  
    {  
          this.pos=0;  
  //this.max=100;  
  this.Update();  
    }  
    var   PB=new   TProgressBar("mypb")  
    PB.Create()  
    PB.max=100;  
  function   test(){  
    //for(i=0;i<5;++i){  
        PB.pos++;  
  //   }  
        PB.Update();  
        if(PB.percent!=100)setTimeout("test();",100);  
  }  
  //-->  
  </SCRIPT>  
  <input   type=button   οnclick="test()"   value=add>  
  <input   type=button   οnclick="PB.Reposition()"   value=clear>  
  </BODY>  
  </HTML>  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值