• 66.环形加载动画(canvas/svg)


    <!DOCTYPE html>
    <html lang="en">
    
    <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>Document</title>
        <style>
            body {
                margin: 0;
                padding: 0;
                text-align: center;
            }
        </style>
    </head>
    
    <body>
        <canvas id="canvas"></canvas>
        <script>
            let canvasWidth = 200;
            let canvasHeight = 200;
            let centerX = canvasWidth / 2;
            let centerY = canvasHeight / 2;
            let r = canvasWidth / 2 - 10;
            let canvas = document.getElementById('canvas');
            canvas.width = canvasWidth;
            canvas.height = canvasHeight;
            let ctx = canvas.getContext('2d');
            let sRad = Math.PI * 2;
            let step = 0;
    
    
            function loading() {
                ctx.beginPath();
                ctx.clearRect(0, 0, canvasWidth, canvasHeight);
                ctx.strokeStyle = "orange";
                ctx.font = "26px Arial";
                ctx.textAlign = "center";
                ctx.fillStyle = "orange";
                ctx.lineWidth = 10;
                let text = parseInt(parseFloat(step) * 100) + '%'
                ctx.fillText(text, centerX, centerY);
                ctx.arc(centerX, centerY, r, 0, sRad * step, false);
                ctx.stroke();
            }
    
            function render() {
    
                if (step > 1) {
                    cancelAnimationFrame(render)
                    return
                }
                requestAnimationFrame(render);
                step += 0.01;
                loading()
    
            }
            render()
        </script>
    </body>
    
    </html>
    

     //svg

    <!DOCTYPE html>
    <html lang="en">
    
    <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>SVG</title>
        <style>
            body {
                background: #1a1a1a;
    
            }
    
            body>div {
                text-align: center;
            }
    
            .ring_circle {
                stroke-dasharray: 10 20;
                transition: stroke-dasharray 0.35s;
            }
        </style>
    </head>
    
    <body>
        <div>
            <svg class="progress-ring" width="120px" height="120px">
                <circle class="ring_circle" stroke="white" stroke-width="4" fill="transparent" r="52" cx="60" cy="60" />
            </svg>
    
        </div>
        <script>
            let circle = document.querySelector('.ring_circle');
            let radius = circle.r.baseVal.value;
            var circrumference = radius * Math.PI * 2;
            circle.style.strokeDasharray = circrumference + " " + circrumference;
            circle.style.strokeDashoffset = circrumference;
            var i = 1;
            var ite = null;
            function setProgress(percent) {
                const offset = circrumference - percent / 100 * circrumference;
                circle.style.strokeDashoffset = offset;
            }
            if (ite) clearInterval(ite);
            ite = setInterval(() => {
                i += 2;
                if (i > 100){
                    i = 100;
                    clearInterval(ite)
                }
                setProgress(i)
            }, 16)
        </script>
    </body>
    
    </html>

     

  • 相关阅读:
    询问js代码
    嵌套查询sql语句例子
    简单的添加更新语句 一条语句实现
    xp序列号
    字符串处理类代码
    上传图片类代码
    关于IE9中jquery ajax提交无法发送cookie的解决方案
    asp.net mvc3分页代码
    System.Timers.Timer在asp.net中的使用方法
    SQL2005连接远程连接配置
  • 原文地址:https://www.cnblogs.com/famLiu/p/10878093.html
Copyright © 2020-2023  润新知