使用方法:
.box{ animation: rotate 1s cubic-bezier(0.4,0.1,0.5,1) 0.1s infinite alternate; } @keyframes rotate { from { Properties:Properties value; } Percentage { Properties:Properties value; } to { Properties:Properties value; } } 或者全部写成百分比的形式: @keyframes rotate { 0% { Properties: value; } Percentage { Properties: value; } 100% { Properties: value; } }
<div class="wobble"> .wobble{ animation: wobble 5s; width : 80px; height : 80px; background : red; border-radius : 40px; margin: 0; } @keyframes wobble { 0% { margin-left: 100px; background: green; } 40% { margin-left: 150px; background: orange; } 60% { margin-left: 75px; background: blue; } 100% { margin-left: 100px; background: red; } }
<div id="mix" class="div"> <i class="fa fa-check"> </div> .mix{ animation-name: rotate; animation-duration: 1s; animation-iteration-count:2;/*播放动画的循环次数,默认为1,infinite为无限次数循环*/ animation-direction:alternate;/*只有两个值,默认值为normal[每次循环都是向前播放]另一个值是alternate[动画播放在第偶数次向前播放,第奇数次向反方向播放]*/ } @keyframes rotate { 0% { transform : rotate(0deg); } 50% { background: #f00; transform : rotate(180deg); } 80%{ transform :translate(100px) } 100% { background: #000; transform : rotate(270deg); } } $('#mix').click(function(){ $(this).toggleClass('mix'); });
animation-name: none | IDENT[,none | IDENT]*;
animation-duration:
animation-timing-function:ease | linear | ease-in | ease-out | ease-in-out | cubic-bezier(x1,y1,x2,y2)]; animation-timing-function:cubic-bezier(0.4,0.1,0.5,1);
/*播放动画的循环次数,默认为1,infinite为无限次数循环*/ animation-iteration-count:2;
/*指定元素动画播放的方向,其只有两个值,默认值为normal,如果设置为normal时,动画的每次循环都是向前播放;另一个值是alternate,他的作用是,动画播放在第偶数次向前播放,第奇数次向反方向播放*/ animation-direction:alternate;
animation-fill-mode:forwards; none 不改变默认行为。 forwards 当动画完成后,保持最后一个属性值(在最后一个关键帧中定义)。 backwards 在 animation-delay 所指定的一段时间内,在动画显示之前,应用开始属性值(在第一个关键帧中定义)。 both 向前和向后填充模式都被应用。
使用方法:
// W3c标准:animationstart animationiteration animationend // // Webkit:webkitAnimationStart webkitAnimationIteration webkitAnimationEnd // // Firefox:animationstart animationiteration animationend // // Opera:animationstart animationiteration animationend // // IE10:MSAnimationStart MSAnimationIteration MSAnimationEnd $("#mix").one("webkitAnimationStart",function(){ console.log('webkitAnimationStart'); }).one("webkitAnimationIteration",function(){ console.log('webkitAnimationIteration'); }).one("webkitAnimationEnd",function(){ console.log('webkitAnimationEnd'); });