溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

css3如何實現(xiàn)圓形旋轉(zhuǎn)倒計時

發(fā)布時間:2021-05-21 11:23:01 來源:億速云 閱讀:450 作者:小新 欄目:web開發(fā)

這篇文章將為大家詳細講解有關css3如何實現(xiàn)圓形旋轉(zhuǎn)倒計時,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。

很多答題的H5界面上有旋轉(zhuǎn)倒計時的效果,一個不斷旋轉(zhuǎn)減少的動畫,類似于下圖的這樣。

css3如何實現(xiàn)圓形旋轉(zhuǎn)倒計時

今天研究了下,可以通過border旋轉(zhuǎn)得到。一般我們可以通過border得到一個四段圓。

css3如何實現(xiàn)圓形旋轉(zhuǎn)倒計時

See the Pen circle by stoneniqiu (@stoneniqiu) on CodePen.

 接下來接可以通過旋轉(zhuǎn)的方式形成一個倒計時的效果:

See the Pen circle-rotate by stoneniqiu (@stoneniqiu) on CodePen.

 一開始旋轉(zhuǎn)45度是為了讓半圓剛好立起來。然后旋轉(zhuǎn)一百八十度。

 .rightcircle{
                border-top: .4rem solid #8731fd;
                border-right: .4rem solid #8731fd;
                right: 0;
                transform: rotate(45deg)
            }
 .right_cartoon {
                -webkit-animation: circleProgressLoad_right 10s linear infinite forwards;
                animation: circleProgressLoad_right 10s linear infinite forwards;
            }
 @keyframes circleProgressLoad_right {
                0% {
                    -webkit-transform: rotate(46deg);
                    transform: rotate(46deg)
                }
                50%,to {
                    -webkit-transform: rotate(-136deg);
                    transform: rotate(-136deg)
                }
            }

畢竟不是真正的減少,要出現(xiàn)一種顏色占大多數(shù)就可以通過兩個半圓來拼湊。

See the Pen circle-timer by stoneniqiu (@stoneniqiu) on CodePen.
 

css3如何實現(xiàn)圓形旋轉(zhuǎn)倒計時

 @keyframes circleProgressLoad_left {
                0%,50% {
                    -webkit-transform: rotate(46deg);
                    transform: rotate(46deg)
                }           
                to {
                    -webkit-transform: rotate(-136deg);
                    transform: rotate(-136deg)
                }
            }

注意到是右邊線轉(zhuǎn)5秒,然后左邊再等五秒,這里css動畫的效果略有不同,右邊是0%開始,50%,to。左邊是0%,50%,然后to,這樣實現(xiàn)的5秒等待。這就是旋轉(zhuǎn)倒計時的效果,最后還可以通過修改左半環(huán)border-left的顏色,來凸顯最后幾秒鐘的緊急情況。

關于“css3如何實現(xiàn)圓形旋轉(zhuǎn)倒計時”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI