很多答題的H5界面上有旋轉(zhuǎn)倒計時的效果,一個不斷旋轉(zhuǎn)減少的動畫,類似于下圖的這樣。
今天研究了下,可以通過border旋轉(zhuǎn)得到。一般我們可以通過border得到一個四段圓。
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.
@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)倒計時,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對VeVb武林網(wǎng)網(wǎng)站的支持!
新聞熱點
疑難解答