<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
.box{
450px;
border: 1px solid #666666;
height: 25px;
margin: 100px auto;
}
#bar{
display: block;
background: red;
float: left;
height: 100%;
text-align: right;
line-height: 25px;
font-size: 25px;
color: #fff;
}
</style>
</head>
<body>
<div id="box" class="box">
<div id="bar"></div>
</div>
<script type="text/javascript">
var timer = null;
var w = 0;
var oDiv = document.getElementById("bar");
var oBox = document.getElementById("box")
timer = setInterval(function(){
w += oBox.offsetWidth/100;
oDiv.style.width = w + 'px';
oDiv.innerHTML = Math.floor(w/oBox.offsetWidth*100)+'%';
if(w >= oBox.offsetWidth){
clearInterval(timer);
oDiv.style.width = oBox.offsetWidth-2 + 'px'
}
},100)
</script>
</body>
</html>