用svg實現一個環形進度條


svg實現環形進度條需要用到的知識:

1、會使用path的d屬性畫一個圓環

//用svg的path元素的A命令畫圓

<path
    d="
        M cx cy
        m 0 -r 
        a r r 0 1 0 0 2r 
        a r r 0 1 0 0 -2r"
>
></path>

//cx cy起點   r  半徑

 

2、熟悉stroke,stroke-linecap,stroke-width,stroke-dasharray、stroke-dashoffset

 

話不多說,直接上代碼

<div style="width: 200px;height: 200px;">
    <svg viewBox="0 0 100 100">
        <path
            d="M 50 50 m -40 0 a 40 40 0 1 0 80 0  a 40 40 0 1 0 -80 0"
            fill="none"
            stroke="#e5e9f2"
            stroke-width="5">
        ></path>
        <path
            d="M 50 50 m -40 0 a 40 40 0 1 0 80 0  a 40 40 0 1 0 -80 0"
            fill="none"
            stroke="#20a0ff"
            stroke-linecap="round"
            class="my-svg-path"
            transform="rotate(90,50,50)"
            stroke-width="5">
        </path>
    </svg>
</div>
.my-svg-path{
    stroke-dasharray: 252.2px, 252.2px;
    stroke-dashoffset: 22px;
    transition: stroke-dashoffset 0.6s ease 0s, stroke 0.6s ease 0s;
    transform: rotateZ(90deg);
    transform-origin: 50% 50%;
}

效果:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM