日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

CSS3實現(xiàn)圓環(huán)進度條

 新進小設(shè)計 2021-09-25

摘要:圓環(huán)進度條被應(yīng)用于各個場景,比如我們可以用來表示加載進度等。通常我們可以用 css3 的動畫去實現(xiàn)。

詳解 css3 實現(xiàn)圓環(huán)進度條

簡單的畫一個圓環(huán),我們都知道如何使用 css 畫一個圓環(huán)。(利用border屬性、border-radius屬性)

HTML 代碼:

<div class="circle></div>

 CSS 代碼:

.circle{
  width:160px;
  height:160px;
  border:20px solid red;
  border-radius:50%;            
}

 實現(xiàn)圓環(huán)進度條屬性,我們利用 css 畫扇形,然后結(jié)合 css3 的動畫屬性去實現(xiàn)。結(jié)合代碼去講解:

HTML代碼:

<div class="circle-progress">
        <div class="content left">
            <div class="circle left-circle"></div>
        </div>
        <div class="content right">
            <div class="circle right-circle"></div>
        </div>
    </div>

 

 首先確定圓環(huán)進度條最外層 css 的屬性:

 .circle-progress {
            position: relative;
            width: 200px;
            height: 200px;
            border: 1px solid #888;  /*可選屬性,僅供測試使用*/
        }

然后定位 content 以及 left 和 right 的屬性值:

.content {
            position: absolute;
            top: 0;
            width: 100px;
            height: 200px;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
        
        .left {
            left: 0;
        }
        
        .right {
            right: 0;
        }

 

最后確定 left-circle 和 right-circle 屬性:

 .circle {
            position: absolute;
            margin: 0;
            width: 160px;
            height: 160px;
            border-radius: 50%;
            border: 20px solid transparent;
            transform: rotate(135deg);
        }
        
        .left-circle {
            left: 0;
            border-top-color: green;
            border-left-color: green;
            animation: circle-left 5s linear infinite;
        }
        
        .right-circle {
            right: 0;
            border-bottom-color: green;
            border-right-color: green;
            animation: circle-right 5s linear infinite;
        }

 

動畫 css3 代碼:

  @keyframes circle-right {
            0% {
                transform: rotate(135deg);
            }
            50%,
            100% {
                transform: rotate(315deg);
            }
        }
        
        @keyframes circle-left {
            0%,
            50% {
                transform: rotate(135deg);
            }
            100% {
                transform: rotate(315deg);
            }
        }

 

 

完整的代碼:

<!DOCTYPE html>
<html>

<head>
    <title>圓環(huán)進度條</title>
    <meta charset="utf-8" name="viewport" content="width=device-width;initial-scale=1.0" />
    <style type="text/css">
        html,
        body {
            width: 100%;
            height: 100%;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        
        .circle-progress {
            position: relative;
            width: 200px;
            height: 200px;
            border: 1px solid #888;
        }
        
        .content {
            position: absolute;
            top: 0;
            width: 100px;
            height: 200px;
            margin: 0;
            padding: 0;
            overflow: hidden;
        }
        
        .left {
            left: 0;
        }
        
        .right {
            right: 0;
        }
        
        .circle {
            position: absolute;
            margin: 0;
            width: 160px;
            height: 160px;
            border-radius: 50%;
            border: 20px solid transparent;
            transform: rotate(135deg);
        }
        
        .left-circle {
            left: 0;
            border-top-color: green;
            border-left-color: green;
            animation: circle-left 5s linear infinite;
        }
        
        .right-circle {
            right: 0;
            border-bottom-color: green;
            border-right-color: green;
            animation: circle-right 5s linear infinite;
        }
        
        @keyframes circle-right {
            0% {
                transform: rotate(135deg);
            }
            50%,
            100% {
                transform: rotate(315deg);
            }
        }
        
        @keyframes circle-left {
            0%,
            50% {
                transform: rotate(135deg);
            }
            100% {
                transform: rotate(315deg);
            }
        }
    </style>
</head>

<body>
    <div class="circle-progress">
        <div class="content left">
            <div class="circle left-circle"></div>
        </div>
        <div class="content right">
            <div class="circle right-circle"></div>
        </div>
    </div>
</body>

</html>

 

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多