且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使循环动画等待使用css3

更新时间:2022-10-21 20:41:13

添加0.5秒到您的动画持续时间,然后在关键帧中创建一个不会改变旋转量的额外框架;

  @  -  webkit-keyframes rotate {
0%{
-webkit-transform:rotate(0deg);
}
83%{/*2.4 / 2.9 = 0.827 * /
-webkit-transform:rotate(360deg);
}
100%{
-webkit-transform:rotation(360deg);
}
}
.animated {
...
-webkit-animation-duration:2.9s; / *注意增加* /
...
}

小连结



I have a css3 animation with the following:

@-webkit-keyframes rotate {
    from {
    -webkit-transform: rotate(0deg);
    }
    to { 
    -webkit-transform: rotate(360deg);
    }
}

.animated {
-webkit-animation-name: rotate;
-webkit-animation-duration: 2.4s;
-webkit-animation-iteration-count: infinite;
-webkit-transition-timing-function: ease-in-out;
}

It works flawlessly, well..., I want to make it wait between the loops:
animation-start, animation-finish, wait(about 0.5s), animation start, animation end, wait(about 0.5s)...

PS: I've tried -webkit-animation-delay, it does not work.

Any help?

Add 0.5 seconds to your animation duration, then create an extra frame in your keyframes that doesn't change the rotation amount;

@-webkit-keyframes rotate {
    0% {
    -webkit-transform: rotate(0deg);
    }
    83% { /*2.4 / 2.9 = 0.827*/
    -webkit-transform: rotate(360deg);
    }
    100% {
    -webkit-transform: rotate(360deg);
    }
}
.animated {
...
-webkit-animation-duration: 2.9s; /*note the increase*/
...
}

Little demo: little link.