<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>进度条</title>
<style>
* {
margin: 0;
padding: 0;
}
#box {
padding: 10px;
width: 400px;
background: #cccccc;
box-shadow: 0 0 5px #000;
}
#progress {
width: 0;
color: #fff;
line-height: 40px;
text-align: center;
background: blue;
overflow: hidden;
}
</style>
<script>
window.onload = function () {
var oPragress = document.getElementById('progress'),
iWidth = 0,
iTimer = null;
iTimer = setInterval(function () {
iWidth += 10;
oPragress.style.width = iWidth + 'px';
oPragress.innerHTML = Math.round(iWidth /400 *100) + '%';
//清除定时器
if(iWidth === 400){
clearInterval(iTimer);
}
},50);
}
</script>
</head>
<body>
<div id="box">
<div id="progress">0%</div>
</div>
</body>
</html>