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的顏色,來凸顯最後幾秒鐘的緊急情況。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.