<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>CSS3动画</title> 
<style>
#animated_div
{
width:76px;
height:47px;
background:#92B901;
color:#ffffff;
position:relative;
font-weight:bold;
font-size:20px;
padding:10px;
animation:animated_div 5s 1;/* @keyframes(关键帧动画),动画名称,开始到结束时间,重复几次 */
-moz-animation:animated_div 5s 1;
-webkit-animation:animated_div 5s 1;
-o-animation:animated_div 5s 1;
border-radius:5px;
-webkit-border-radius:5px;
}

@keyframes animated_div
{
0%      {transform: rotate(0deg);left:0px;}
25%     {transform: rotate(20deg);left:0px;}
50%     {transform: rotate(0deg);left:500px;}
55%     {transform: rotate(0deg);left:500px;}
70%     {transform: rotate(0deg);left:500px;background:#1ec7e6;}
100%    {transform: rotate(-360deg);left:0px;}
}

/* Safari and Chrome */
@-webkit-keyframes animated_div
{
0%      {-webkit-transform: rotate(0deg);left:0px;}
25%     {-webkit-transform: rotate(20deg);left:0px;}
50%     {-webkit-transform: rotate(0deg);left:500px;}
55%     {-webkit-transform: rotate(0deg);left:500px;}
70%     {-webkit-transform: rotate(0deg);left:500px;background:#1ec7e6;}
100%    {-webkit-transform: rotate(-360deg);left:0px;}
}

/* Firfox */
@-moz-keyframes animated_div
{
0%   {-moz-transform: rotate(0deg);left:0px;}
25%  {-moz-transform: rotate(20deg);left:0px;}
50%  {-moz-transform: rotate(0deg);left:500px;}
55%  {-moz-transform: rotate(0deg);left:500px;}
70%  {-moz-transform: rotate(0deg);left:500px;background:#1ec7e6;}
100% {-moz-transform: rotate(-360deg);left:0px;}
}

/* Opera */
@-o-keyframes animated_div
{
0%   {transform: rotate(0deg);left:0px;}
25%  {transform: rotate(20deg);left:0px;}
50%  {transform: rotate(0deg);left:500px;}
55%  {transform: rotate(0deg);left:500px;}
70%  {transform: rotate(0deg);left:500px;background:#1ec7e6;}
100% {transform: rotate(-360deg);left:0px;}
}
</style>
<h2>CSS3 动画</h2>
<hr>
<div id="animated_div">CSS3<br><span style="font-size:10px">动画</span>
</div>

</body>
</html>

简略写法和完整写法

-webkit-animation:myfirst 5s linear 2s infinite alternate;

-webkit-animation-name:myfirst;
-webkit-animation-duration:5s;
-webkit-animation-timing-function:linear;
-webkit-animation-duration:2s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:alternate;

标签:前端

你的评论