前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >SVG实现圆形进度条

SVG实现圆形进度条

作者头像
越陌度阡
发布2020-11-26 10:29:35
1.4K0
发布2020-11-26 10:29:35
举报

给大家分享一个用SVG实现圆形进度条的特效,效果如下:

在这里插入图片描述
在这里插入图片描述

以下是代码实现,欢迎大家复制粘贴和收藏。

代码语言:javascript
复制
<!DOCTYPE html>
<html lang="en">

<head>

    <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>
            * {
                margin: 0;
                padding: 0;
                box-sizing: border-box;
                font-family: '微软雅黑', sans-serif;
            }

            body {
                display: flex;
                align-items: center;
                justify-content: center;
                min-height: 100vh;
                background: #000;
            }

            .box {
                position: relative;
                width: 300px;
                height: 400px;
                display: flex;
                justify-content: center;
                align-items: center;
                margin-right: 60px;
                flex-direction: column;
                background: linear-gradient(to right, rgba(35, 35, 35, 0.2), #1e1d1e);
                box-shadow: 0 30px 60px rgba(0, 0, 0, 0.2);
            }


            .box .percent {
                position: relative;
                width: 150px;
                height: 150px;
            }

            .box .percent svg {
                position: relative;
                width: 150px;
                height: 150px;
            }

            .box .percent svg circle {
                width: 150px;
                height: 150px;
                fill: none;
                stroke-width: 10;
                stroke: #000;
                transform: translate(5px, 5px);
                stroke-dasharray: 440;
                stroke-dashoffset: 440;
                stroke-linecap: round;
            }


            .box:nth-child(1) .percent svg circle:nth-child(1) {
                stroke-dashoffset: 0;
                stroke: #000
            }

            .box:nth-child(1) .percent svg circle:nth-child(2) {
                stroke-dashoffset: calc(440 - (440 * 87)/100);
                stroke: #00fe41;
            }

            .box:nth-child(2) .percent svg circle:nth-child(1) {
                stroke-dashoffset: 0;
                stroke: #000
            }

            .box:nth-child(2) .percent svg circle:nth-child(2) {
                stroke-dashoffset: calc(440 - (440 * 85)/100);
                stroke: #079eff;
            }

            .box:nth-child(3) .percent svg circle:nth-child(1) {
                stroke-dashoffset: 0;
                stroke: #000
            }

            .box:nth-child(3) .percent svg circle:nth-child(2) {
                stroke-dashoffset: calc(440 - (440 * 60)/100);
                stroke: #c304fe;
            }

            .box:hover {
                transform: translateY(-20px);
                transition: all 0.5s;
            }

            .box:hover .number {
                transform: scale(1.2);
                transition: all 0.5s;
                color: #fff !important;
            }

            .box:hover .text {
                transform: scale(1.2);
                transition: all 0.5s;
                color: #fff !important;
            }


            .box .percent .number {
                position: absolute;
                top: 0;
                left: 0;
                width: 100%;
                height: 100%;
                display: flex;
                justify-content: center;
                align-items: center;
                color: #767576;
            }

            .box .percent .number h2 {
                font-size: 48px;
            }

            .box .percent .number span {
                font-size: 24px;
            }

            .box .text {
                padding: 10px 0 0;
                color: #999;
                font-weight: 700;
                letter-spacing: 1px;
            }
        </style>
    </head>
</head>

<body>
    <div class="box">
        <div class="percent">
            <svg>
                <circle cx='70' cy='70' r='70'></circle>
                <circle cx='70' cy='70' r='70'></circle>
            </svg>
            <div class="number">
                <h2>87<span>%</span></h2>
            </div>
        </div>
        <h2 class="text">Progress</h2>
    </div>
    <div class="box">
        <div class="percent">
            <svg>
                <circle cx='70' cy='70' r='70'></circle>
                <circle cx='70' cy='70' r='70'></circle>
            </svg>
            <div class="number">
                <h2>85<span>%</span></h2>
            </div>
        </div>
        <h2 class="text">Progress</h2>
    </div>
    <div class="box">
        <div class="percent">
            <svg>
                <circle cx='70' cy='70' r='70'></circle>
                <circle cx='70' cy='70' r='70'></circle>
            </svg>
            <div class="number">
                <h2>60<span>%</span></h2>
            </div>
        </div>
        <h2 class="text">Progress</h2>
    </div>
</body>

</html>
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/06/01 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档