• canvas圆形进度条(逆时针)


    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>circle</title>
    </head>
    <body>
        <canvas id='myCanvas' width="292" height="292"></canvas>
    
        <script>
            // 绘制圆
            function drawCircleFn(totalReward) {
                var canvas = document.getElementById('myCanvas');
                var ctx = canvas.getContext('2d');
                ctx.lineWidth = 24;
                ctx.lineCap = 'round';
                if(totalReward){
                    ctx.strokeStyle = '#0FCC9E';
                    circleAnimateFn(ctx);
                }else{
                    ctx.strokeStyle = '#f2f2f2';
                    circleNoAnimateFn(ctx);
                }
            }
    
            // 绘制灰色圆
            function circleNoAnimateFn(ctx) {
                let startAngle = 3 / 2 * Math.PI; //开始位置弧度
                let percentage = 10;
                let diffAngle = percentage / 100 * Math.PI * 2; //完成进度弧度值
                ctx.beginPath();
                ctx.arc(146, 146, 132, startAngle, diffAngle + startAngle, true);
                ctx.stroke();
            }
    
            // 绘制动画圆
            function circleAnimateFn(ctx) {
                let startAngle = 3 / 2 * Math.PI; //开始位置弧度
                let percentage = 100;  //完成进度值 100 - 10
                let endcentage = 10;
                let diffAngle = percentage / 100 * Math.PI * 2; //完成进度弧度值
                let intervalFn = setInterval(function(){
                    if(percentage <= endcentage){
                        clearInterval(intervalFn);
                        percentage = endcentage;
                    }else{
                        percentage = percentage - 5;
                        diffAngle = percentage / 100 * Math.PI * 2;
                        ctx.beginPath();
                        ctx.arc(146, 146, 132, startAngle, diffAngle + startAngle, true);
                        ctx.stroke();
                    }
                }, 15)
            }
    
            drawCircleFn();
        </script>
    </body>
    </html>
  • 相关阅读:
    做好测试计划和测试用例的工作的关键是什么?
    windows创建虚拟环境
    面试题整理
    【爬虫】使用selenium设置cookie
    【爬虫】随机获取UA
    Scrapy爬虫提高效率
    【爬虫】多线程爬取糗事百科写入文件
    【爬虫】多线程爬取表情包
    【爬虫】Condition版的生产者和消费者模式
    【爬虫】Load版的生产者和消费者模式
  • 原文地址:https://www.cnblogs.com/muou2125/p/11189135.html
Copyright © 2020-2023  润新知