<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>刻度进度条</title>
</head>
<canvas id="dialCanvas" width="1000px" height="1000px">
<span>您的浏览器不支持canvsa,请您更换浏览器试试</span>
</canvas>
<body>
<script>
const percent = 360
let count = 120
const mycanvas = document.getElementById('dialCanvas');
const ctx = mycanvas.getContext('2d');
console.log('mycanvas.width, mycanvas.height',mycanvas.width, mycanvas.height)
//画进度条函数
function process(ctx,percent) {
//画刻度盘
for(let i = 120 ; i < 420 ; i++ ) {
if(i%4===0) {
ctx.beginPath();
ctx.arc(500, 500, 100, Math.PI/180*i, Math.PI/180*(i+1), false); // 绘制
ctx.strokeStyle = '#EDEDED';
ctx.lineWidth = 30;
ctx.stroke();
}
}
//画进度条
for(let i = 120 ; i <=percent ; i++ ) {
if(i%4===0 && i < percent ) {
ctx.beginPath();
ctx.arc(500, 500, 100, Math.PI/180*i, Math.PI/180*(i+1), false); // 绘制
ctx.strokeStyle = ' #FF82AB';
ctx.lineWidth = 30;
ctx.stroke();
} else if ( i === percent ) {
ctx.beginPath();
ctx.arc(500, 500, 100, Math.PI/180*i, Math.PI/180*(i+1), false); // 绘制
ctx.strokeStyle = ' #FF82AB';
ctx.lineWidth = 50;
ctx.stroke();
}
}
}
let time = setInterval( ()=>{
if( count <= percent ) {
ctx.clearRect(0, 0,mycanvas.width, mycanvas.height);
process(ctx,count)
} else if ( count > percent ) {
clearInterval(time)
console.log('count',count)
}
count++
},10)
</script>
<style>
</style>
</body>
</html>