zoukankan      html  css  js  c++  java
  • react 实现圆环进度条

    import React, { useState, useEffect } from "react"
    import { css } from "emotion"

        //num是从父级传来的百分比数值

    export default function({ num }) {
    let rightTrnas = css`
          transform: rotate(0deg);
    `
    let leftTrnas = css`
         transform: rotate(${0}deg);
     `
    if (num <= 180) {
        rightTrnas = css`
           transform: rotate(${(Math.round(num * 100) / 100) * 3.6}deg);
        `
    } else {
         rightTrnas = css`
            transform: rotate(180deg);
         `
         leftTrnas = css`
           transform: rotate(${(Math.round(num * 100) / 100) * 3.6 - 180}deg);
    `
    }
    return (
            <div className={circleCss}>
                   <div className="circle">
                         <div className="pie_left">
                              <div className={`left ${leftTrnas}`}></div>
                        </div>
                        <div className="pie_right">
                              <div className={`right ${rightTrnas}`}></div>
                        </div>
                       <div className="mask">
                                <span>{Math.round(num * 100) / 100}</span>%
                        </div>
                  </div>
             </div>
         )
    }
    const circleCss = css`
             display: flex;
             justify-content: center;
             align-items: center;
             & .circle {
                50px;
                height: 50px;
                position: relative;
                border-radius: 50%;
                background: #e9e9e9;
             }
           & .pie_left,
           & .pie_right {
                50px;
               height: 50px;
               position: absolute;
               top: 0;
               left: 0;
            }
           & .left,
           & .right {
                50px;
                height: 50px;
                background: #ff721c;
                border-radius: 50%;
                position: absolute;
                top: 0;
                left: 0;
              }
          & .pie_right,
          & .right {
              clip: rect(0, auto, auto, 25px);
           }
          & .pie_left,
          & .left { 
               clip: rect(0, 25px, auto, 0);
          }
          & .mask {
                44px;
                height: 44px;
                border-radius: 50%;
                left: 3px;
                top: 3px;
                background: #fff;
                position: absolute;
                text-align: center;
                line-height: 44px;
                font-size: 12px;
                color: #ff721c;
           }
      `
    如果要修改圆环的大小修改宽高和left ,right中的 clip: rect的值即可
  • 相关阅读:
    在Node.js环境下使用npm命令安装OpenLayers6.4.3时,提示错误“rollbackFailedOptional: verb npm-session”的解决办法
    Windows7-64环境中部署OpenLayers6.4.3详细步骤
    Navicat 导出csv数据乱码如何处理?
    Win10 如何右键新建.md文件
    关于loading加载的问题
    X度文库越来越不要脸了!
    Layui date 插件 闪烁 无法选择
    每日识字
    如何生成项目目录结构
    小米招聘 hiring
  • 原文地址:https://www.cnblogs.com/cnlg123/p/12066758.html
Copyright © 2011-2022 走看看