css3實現圓形旋轉倒計時代碼分享

來源:互聯網
上載者:User
很多答題的H5介面上有旋轉倒計時的效果,一個不斷旋轉減少的動畫,類似於的這樣。本文主要和大家介紹了css3 實現圓形旋轉倒計時功能,需要的朋友可以參考下,希望能協助到大家。

今天研究了下,可以通過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的顏色,來凸顯最後幾秒鐘的緊急情況。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.