进度条的实现


<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>进度条demo</title>
<script src="http://cdn.bootcss.com/jquery/2.1.4/jquery.js"></script>
<style>
progress { width: 160px;height:14px;border: 1px solid #ffd022; background-color:#e6e6e6; color: #ffd022; /*IE10*/}
progress::-moz-progress-bar { background: #ffd022; }
progress::-webkit-progress-bar { background: #ffd022; }
progress::-webkit-progress-value { background: #ffd022; }
progress::-webkit-progress-bar { background: #e6e6e6; }
</style>
</head>
<body>
<input id="btn" type="button" οnclick="update()" value="update">
<br>
<span>bar.totalCount:<span id="bar-count"></span></span>
<br>
<span>progress.value:<span id="bar-value"></span></span>
<br>
<progress value="" max="" id="myBar"></progress>
<script type="text/javascript">

//进度条类
function ProgressHandler() {
this.currentIndex = 0;
this.totalCount=0;
this.progress = {};
}

//初始化进度条方法,需传入总长度
ProgressHandler.prototype.init = function (totalCount) {
this.totalCount=totalCount;
this.progress.max=this.totalCount;

$('#myBar').attr('max',totalCount);
}

//更新进度条
ProgressHandler.prototype.update = function () {
this.currentIndex++;
this.currentIndex = this.currentIndex>this.totalCount?this.totalCount:this.currentIndex;
this.progress.value=this.currentIndex;

//调用方法更新页面
rendor();
}

//进度条reset方法
ProgressHandler.prototype.reset = function () {
this.totalCount=0;
this.currentIndex=0;
}

//判断是否完成的方法
ProgressHandler.prototype.isFinished = function(){
if(this.progress.value==this.totalCount){
return true;
}else{
return false;
}
}

//更新dom
function rendor(){
$('#bar-value').html(bar.progress.value);
$('#bar-count').html(bar.totalCount);
$('#myBar').val(bar.progress.value);
if(bar.isFinished()){
$('#myBar').hide();
}
}

//创建对象
var bar = new ProgressHandler();
bar.init(10);

//更新方法
function update(){
bar.update();
console.log(bar);
}
</script>
</body>
</html>

转载于:https://www.cnblogs.com/wangjiaojiao/p/4600267.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值