进度条是用来表示:某件事完成量的百分比,有很多情况下我们都会用到它!
我用js代码写了一个进度条,样式可能不是很漂亮!为了进度量不是一个等差数列,我用随机数来做进度数列的差值
下是代码:(还望朋友们指正!)
<html>
<head>
<title>js 进度条</title>
</head>
<body>
<p align="center">
<span id="show" style="border:1px solid red;width:800px;height:30px;">
<hr id="bar" align="left" style="height:30px;width:0px;" color="red">
</span>
<span id="total"></span>
</p>
</body>
<script language="JavaScript">
var per=0;
function run(){
per+=parseInt(Math.random()*1000000%20);
document.getElementById("bar").style.width=per;
if(per>=800)per=800;
document.getElementById("total").innerHTML=parseInt((per/800)*100)+'%';
if(per>=800){
clearTimeout(timeout);
return;
}
var timeout=setTimeout("run()",100);
}
οnlοad=run();
</script>
</html>
下面是附件,朋友们可以下载下来看看效果!