不少答题的H5界面上有旋转倒计时的效果,一个不断旋转减小的动画,相似于下图的这样。css
今天研究了下,能够经过border旋转获得。通常咱们能够经过border获得一个四段圆。web
See the Pen circle by stoneniqiu (@stoneniqiu) on CodePen.动画
接下来接能够经过旋转的方式造成一个倒计时的效果:spa
See the Pen circle-rotate by stoneniqiu (@stoneniqiu) on CodePen.code
一开始旋转45度是为了让半圆恰好立起来。而后旋转一百八十度。orm
.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) } }
毕竟不是真正的减小,要出现一种颜色占大多数就能够经过两个半圆来拼凑。blog
See the Pen circle-timer by stoneniqiu (@stoneniqiu) on CodePen.ci
@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的颜色,来凸显最后几秒钟的紧急状况。rem