<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<style>
#first {
width: 520px;
margin: 20px auto;
height: 30px;
border: 1px solid black;
position: relative;
border-radius: 10px;
overflow: hidden;
background-color: gainsboro;
}
#second {
background-color: red;
width: 10px;
height: 30px;
position: absolute;
text-align: right;
line-height: 30px;
color: white;
}
</style>
<body>
<div id="first">
<div id="second"><span id="third">0</span>%</div>
</div>
<script>
var _second= document.getElementById("second");
var _third=document.getElementById("third");
var i = 0;
var id = setInterval(frame, 100);
function frame() {
if (i == 100) {
clearInterval(id);
_second.innerHTML="加载已完成";
} else {
i++;
_third.innerText=i;
_second.style.width = i + '%';
}
}
</script>
</body>
</html>
08-11
1302
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
12-23
2046
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)