zoukankan      html  css  js  c++  java
  • Css3 实现全圆进度条展示功能

    一、Css3 实现全圆进度条展示功能1

    <style>
        .block {
            width: 200px;
            height: 200px;
            background: rgb(247, 49, 49);
            position: relative;
            border-radius: 50%;
        }
    
        .block>.block {
            position: absolute;
        }
    
        .block2 {
            clip: rect(0, 100px, auto, auto);
            background: #aaa;
        }
    
        .block3 {
            background: #aaa;
            clip: rect(0, auto, auto, 100px);
            transform: rotate(45deg);
        }
    </style>
    
    <div class="block block1">
        <div class="block block2"></div>
        <div class="block block3"></div>
    </div>
    
    <script>
        $(function () {
            var percent = 60;
            var baseColor = $('.block').css('background-color');
            if (percent <= 50) {
                $('.block3').css('transform', 'rotate(' + (percent * 3.6) + 'deg)');
            } else {
                $('.block3').css({
                    'transform': 'rotate(0deg)',
                    'background-color': baseColor
                });
                $('.block2').css('transform', 'rotate(' + ((percent - 50) * 3.6) + 'deg)');
            }
        })
    </script>

    二、Css3 实现全圆进度条展示功能2

    <style>
        /*支持IE9及以上*/
        .circle-bar {
            font-size: 200px;
            width: 1em;
            height: 1em;
            position: relative;
            background-color: rgb(247, 47, 47);
        }
    
        .circle-bar-left,
        .circle-bar-right {
            width: 1em;
            height: 200px;
            background-color: #ddd;
        }
    
        /*
        这里采用clip剪切了圆,实现左右两个半圆,右半圆在后面,因此在更上一层,
        clip的用法参考:http://www.w3school.com.cn/cssref/pr_pos_clip.asp
        */
        .circle-bar-right {
            clip: rect(0, auto, auto, 0.5em);
        }
    
        .circle-bar-left {
            clip: rect(0, 0.5em, auto, 0);
        }
    
        .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">30%</span>
        </div>
    </div>
    
    <script>
        $(function () {
            var percent = parseInt($('.mask :first-child').text());
            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)');
            }
        })
    </script>

    更多:

    CSS3 圆环旋转效果

    Css 实现半圆进度条展示功能 

    Css3 实现循环留言滚动效果(一) 

  • 相关阅读:
    收集的java面试题
    重载和重写的区别
    java中封装的概念
    java中多态的概念
    vue中的$on,$emit,$once,$off源码实现
    js bind的实现
    对象的深拷贝
    v-for的简单实现
    v-for的显示过滤/排序结果
    ES6的数组方法之Array.from
  • 原文地址:https://www.cnblogs.com/tianma3798/p/13782209.html
Copyright © 2011-2022 走看看