<body>
<canvas id="mycanvas">您的浏览器不支持</canvas>
</body>
<script>
//获取canvas
var canvas = document.getElementById('mycanvas');
//定义画布的大小
canvas.width=1000;
canvas.height=300;
canvas.style.border="1px solid #ccc";
//获取画布环境
var cxt=canvas.getContext("2d");
//定义进度条的外边框
cxt.strokeStyle="blue";
cxt.strokeRect(150,100,500,80);
//进度条的思路:每一秒中画一个小的矩形填充。
cxt.fillStyle="red";
var i=0;
var clear=setInterval(function(){
cxt.fillRect(150+i,100,10,80);
i=i+10;
//判断当进度条到达底部时,停止。
if(i>490){
clearInterval(clear);
}
},100)
</script>
网友评论