【css3】旋轉倒計時


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

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

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

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

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

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

  .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)
                }
            }

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

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)
                }
            }

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


免責聲明!

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



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