效果截图:
Html页:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>进度条</title>
</head>
<body>
<div class="systemUpdates">
<label class="newSystem">An up-to-date system is a healthy system</label><br>
<label class="tips">please wait while system update searches for new updates for your system</label>
<div class="progressBar" id="progressBar">
<div class="barContent" id="barContent"></div>
</div>
<div class="bottomDisplay">
<input type="button" class="cancelButton" value="CANCEL" />
<span class="progress">
<label id="progressShow">0%</label>
<label> complete</label>
</span>
</div>
</div>
</body>
</html>
css样式:
<style type="text/css">
.systemUpdates {
width:780px;
height:200px;
background:#eeeeee;
padding-top:55px;
padding-left:50px;
}
.newSystem {
color:#5e5454;
font-size:28px;
font-weight:bold;
}
.tips {
font-size:8px;
}
.progressBar {
margin-top:30px;
width:720px;
height:8px;
background:#ffffff;
border-radius:5px;
}
.barContent {
height: 8px;
background: #00ff21;
border-radius: 5px;
}
.bottomDisplay {
width: 720px;
height: 100px;
margin-top: 18px;
}
.cancelButton {
width: 110px;
height: 40px;
background: #ffffff;
border: none;
border-radius: 50px;
font-weight: bold;
outline: none;
}
.cancelButton:hover {
color: white;
background: #343238;
}
.progress {
margin-left:510px;
font-size:10px;
}
</style>
JS逻辑:
<script type="text/javascript">
//窗体加载
window.onload = function () {
testBegin(0);
}
//测试开始
function testBegin(val) {
var progressBar = document.getElementById("progressBar");
var barContent = document.getElementById("barContent");
var label = document.getElementById("progressShow");
for (var i = val; i <= 100; i++) {
barContent.style.width = progressBar.offsetWidth * (i / 100) + "px";
label.innerText = ((i) + "%");
window.setTimeout("testBegin(" + ++i + ")", 200)
break;
}
}
</script>