圆环百分比, 圆环等待中(css3)

本文展示了如何使用CSS创建带有百分比显示的圆环效果和动画进度条。通过调整div元素的样式,实现了圆环的左右两部分以展示不同百分比,并通过JavaScript动态设置角度实现百分比变化。同时,还提供了一个圆形进度条的动画效果,利用border属性和关键帧动画来实现旋转。这些技巧在前端开发中常用于制作仪表盘或者加载指示器。

1、圆环百分比
在这里插入图片描述

    <div class="div3">
        <div class="circle">
            <div class="pie-left">
                <div class="left"></div>
            </div>
            <div class="pie-right">
                <div class="right"></div>
            </div>
            <div class="mask"><span></span></div>
        </div>
        <div class="num"><span></span>%</div>
    </div>
        .div3 {
            position: relative;
            display: flex;
            align-items: center;
            min-width: 60px;
            justify-content: flex-start;
            height: 24px;
            width: 22.5%;
        }
        .circle {
            width:24px;
            height: 24px;
            position: absolute;
            border-radius: 50%;
            background: #3F66FF;
            top: 0;
        }
        .num {
            padding-left: 35px;
        }
        .pie-left, 	.pie-right {
            width: 24px;
            height: 24px;
            position: absolute;
            left:0px;
            right: 0px;
        }
        .left, .right {
            display: block;
            width: 24px;
            height: 24px;
            background: #F0F2F5;
            border-radius: 50%;
            position: absolute;
            left:0px;
            top:0px;
            /*旋转30度*/
            /*transform: rotate(30deg);*/
        }
        .pie-right, .right {
            clip:rect(0,auto,auto,12px);
        }
        .pie-left, .left {
            /*截图工具 top rigt,bottom, left*/
            clip:rect(0,12px,auto,0);
        }

        .mask {
            width:16px;
            height: 16px;
            border-radius: 50%;
            position: absolute;
            left: 4px;
            top:4px;
            background: #fff;
        }
        var percent = 40
        var filePercent = Math.ceil(percent)
        var num = Math.ceil(percent)*3.6
        var str = ''
        $('.num span').text(percent)
        if(num < 180) {
            $('.right').css('transform', 'rotate(' + num + 'deg)')
        }else {
            $('.left').css('transform', 'rotate(' + (num - 180) + 'deg)')
            $('.right').css('transform', 'rotate(180deg)')
        }

2、圆环等待

<div class="progress-bar"></div>
        .progress-bar {
            width: 20px;
            height: 20px;
            border: 4px solid #3F66FF;
            border-left-color: #F0F2F5;
            border-right-color: #F0F2F5;
            border-top-color: #F0F2F5;
            margin: 12px;
            border-radius: 50%;
            animation: circle 2s infinite linear;
        }

        @keyframes circle {
            0% {
                transform: rotate(0deg);
            }

            100% {
                transform: rotate(-360deg);
            }
        }
js代码 [removed] var wave = (function () { var ctx; var waveImage; var canvasWidth; var canvasHeight; var needAnimate = false; function init (callback) { var wave = document.getElementById(&#39;wave&#39;); var canvas = document.createElement(&#39;canvas&#39;); if (!canvas.getContext) return; ctx = canvas.getContext(&#39;2d&#39;); canvasWidth = wave.offsetWidth; canvasHeight = wave.offsetHeight; canvas.setAttribute(&#39;width&#39;, canvasWidth); canvas.setAttribute(&#39;height&#39;, canvasHeight); wave.appendChild(canvas); waveImage = new Image(); waveImage.onload = function () { waveImage.onload = null; callback(); } waveImage.src = &#39;images/wave.png&#39;; } function animate () { var waveX = 0; var waveY = 0; var waveX_min = -203; var waveY_max = canvasHeight * 0.7; var requestAnimationFrame = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame || function (callback) { window.setTimeout(callback, 1000 / 60); }; function loop () { ctx.clearRect(0, 0, canvasWidth, canvasHeight); if (!needAnimate) return; if (waveY < waveY_max) waveY = 1.5; if (waveX < waveX_min) waveX = 0; else waveX -= 3; ctx.globalCompositeOperation = &#39;source-over&#39;; ctx.beginPath(); ctx.arc(canvasWidth/2, canvasHeight/2, canvasHeight/2, 0, Math.PI*2, true); ctx.closePath(); ctx.fill(); ctx.globalCompositeOperation = &#39;source-in&#39;; ctx.drawImage(waveImage, waveX, canvasHeight - waveY); requestAnimationFrame(loop); } loop(); } function start () { if (!ctx) return init(start); needAnimate = true; setTimeout(function () { if (needAnimate) animate(); }, 500); } function stop () { needAnimate = false; } return {start: start, stop: stop}; }()); wave.start(); [removed]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值