首页 技术 正文
技术 2022年11月7日
0 收藏 376 点赞 877 浏览 2266 个字

逻辑

1、首先有一个圆:蓝色的纯净的圆,效果:

用HTML、CSS、JS制作圆形进度条(无动画效果)

2、再来两个半圆,左边一个,右边一个将此蓝色的圆盖住,效果:

用HTML、CSS、JS制作圆形进度条(无动画效果)

此时将右半圆旋转60°,就会漏出底圆,效果:

用HTML、CSS、JS制作圆形进度条(无动画效果)

 

然后我们再用一个比底圆小的圆去覆盖这个大圆就可以出进度条效果了

用HTML、CSS、JS制作圆形进度条(无动画效果)

代码:

<style>
     /*支持IE9及以上*/
    .circle-bar {margin: 20px; font-size:200px; width: 1em; height: 1em; position: relative;  background-color: #29a6e6; }
    .circle-bar-left,.circle-bar-right { width: 1em; height: 1em;  }
    /*
        这里采用clip剪切了圆,实现左右两个半圆,右半圆在后面
     */
    .circle-bar-right { clip:rect(0,auto,auto,.5em);background-color: #e2e2e2; }
    .circle-bar-left { clip:rect(0,.5em,auto,0); background-color: red;}

.mask { width: 0.8em; height: 0.8em;  background-color: #fff;text-align: center;line-height: 0.2em; color:rgba(0,0,0,0.5); }
    .mask :first-child { font-size: 0.3em; height: 0.8em; line-height: 0.8em; display: block;  }
    /*所有的后代都水平垂直居中,这样就是同心圆了*/
    .circle-bar * {  position: absolute; top:0; right:0; bottom:0; left:0; margin:auto; }
    /*自身以及子元素都是圆*/
    .circle-bar, .circle-bar > * { border-radius: 50%; }
</style>

<div class=”circle-bar”>
    <div class=”circle-bar-left”></div>
    <div class=”circle-bar-right”></div>
     <!–遮罩层,显示百分比–>
    <div class=”mask”>
        <span class=”percent”></span>
    </div>
</div>

<script>
    $(function () {
        var percent = 0;
        var interval = setInterval(function () {
            //            var percent = parseInt($(‘.mask :first-child’).text());
            percent+=5;
            var baseColor = $(‘.circle-bar’).css(‘background-color’);
            if (percent <= 50) {
                $(‘.circle-bar-right’).css(‘transform’, ‘rotate(‘ + (percent * 3.6) + ‘deg)’);
            } else {
                $(‘.circle-bar-right’).css({
                    ‘transform’: ‘rotate(0deg)’,
                    ‘background-color’: baseColor
                });
                $(‘.circle-bar-left’).css(‘transform’, ‘rotate(‘ + ((percent – 50) * 3.6) + ‘deg)’);
            }
            $(‘.mask :first-child’).html(percent + “%”);
            if (percent == 100) {
                $(‘.circle-bar-right’).css({
                    ‘transform’: ‘rotate(0deg)’,
                    ‘background-color’: ‘#e2e2e2’
                });
                $(‘.circle-bar-left’).css({
                    ‘transform’: ‘rotate(0deg)’,
                    ‘background-color’: ‘#e2e2e2’
                });
                percent = 0;
                clearInterval(interval);
            }
        }, 1000);
    })
</script>

作者:何大必
链接:https://www.jianshu.com/p/e7bd35cd88cf
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,964
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,486
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,331
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,114
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,747
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,781