zoukankan      html  css  js  c++  java
  • 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>

     

  • 相关阅读:
    数组实战---集合了一些常用函数
    PHP正则表达式函数
    ThinkPHP学习之-------视图
    ThinkPHP小技巧之改变应用名称
    ThinkPHP中常用总结一CURD操作
    PHPExcel从数据库导出数据
    用PHP脚本来拆分字符串并形成两个新字段
    PHPExcel导出数据的基本使用方法
    php 中文切割字符串长度
    Nginx 在configure时的参数
  • 原文地址:https://www.cnblogs.com/famLiu/p/10878093.html
Copyright © 2011-2022 走看看