一个部分封装的漂亮进度条

<div style="background: url('http://screenprint2007.cpp114.com/UserFiles/20070412155452218.gif') no-repeat;text-align:center;width:256px;height:18px;position:absolute;top:110;left:10;font-size:13px">
<div id="proc" style="background: url('http://screenprint2007.cpp114.com/UserFiles/20070412155424937.gif');position:absolute;top:0;left:0;width:0px;height:18px;font-size:13px"></div>
<div style="position:absolute;top:2;left:0;width:256px;height:18px;text-align:center;font-size:13px;background:transparent">&nbsp;</div>
</div>
<br><br><br><br><br><br>
<input type="button" value="start" οnclick="processBar.changeMode();if(processBar.isMoving){this.value='Stop';}else{this.value='Start';}">
<script>
document.execCommand("BackgroundImageCache",false,true);
function ProcessBar(obj){
   this.isMoving = false;
   this.maxLength = parseInt(obj.parentNode.style.width.replace("px",""));
   this.nowLength = parseInt(obj.style.width.replace("px",""));
   this.moveInterval = 100;
   this.moveRange = 1;
   this.timer;
   this.obj = obj;

   ProcessBar.nowObj = this;

   this.changeMode = function(){
  this.isMoving = !this.isMoving;
  
  if(this.isMoving){
   this.timer = window.setInterval(ProcessBar.nowObj.moving, this.moveInterval);
  }else{
   window.clearInterval(this.timer);
  }
   }

   this.moving = function(){
        ProcessBar.nowObj.nowLength += ProcessBar.nowObj.moveRange;
  ProcessBar.nowObj.obj.style.width = ProcessBar.nowObj.nowLength;

  ProcessBar.nowObj.obj.parentNode.lastChild.firstChild.data = Math.ceil((ProcessBar.nowObj.nowLength/ProcessBar.nowObj.maxLength)*100) + "%";

  if(ProcessBar.nowObj.nowLength >= ProcessBar.nowObj.maxLength){
   window.clearInterval(ProcessBar.nowObj.timer);
   ProcessBar.nowObj.obj.parentNode.lastChild.firstChild.data = "Complete!";
  }
   }

  
}

var processBar = new ProcessBar(proc);

</script> 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值