您的位置:首页 > Web前端 > CSS

css3的动画animation

2015-08-28 13:17 771 查看
    css3的animation动画可设定元素属性变化的中间多个关键帧,以此设定复杂的动画效果,而transition只能设定开始状态和结束状态两帧。

例子:

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<h1>div从左上角运动到右上角再运动到右下角再运动到左上角同时变色</h1>
<style>
div
{
width:100px;
height:100px;
background:red;
position:relative;

/*指定的动画帧名称 动画时长 变形方式 变形前的等待时间 执行次数 normal为正常,alternate为正逆轮播*/
animation:myfirst 5s linear 0.5s 2 alternate;
-moz-animation:myfirst 5s linear 0.5s 2 alternate;
-webkit-animation:myfirst 5s linear 0.5s 2 alternate;
-o-animation:myfirst 5s linear 0.5s 2 alternate;
}

@keyframes myfirst
{
0% {background:red; left:0px; top:0px;}
25% {background:yellow; left:200px; top:0px;}
50% {background:blue; left:200px; top:200px;}
75% {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}
@-moz-keyframes myfirst /* Firefox */
{
0% {background:red; left:0px; top:0px;}
25% {background:yellow; left:200px; top:0px;}
50% {background:blue; left:200px; top:200px;}
75% {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}
@-webkit-keyframes myfirst /* Safari and Chrome */
{
0% {background:red; left:0px; top:0px;}
25% {background:yellow; left:200px; top:0px;}
50% {background:blue; left:200px; top:200px;}
75% {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}
@-o-keyframes myfirst /* Opera */
{
0% {background:red; left:0px; top:0px;}
25% {background:yellow; left:200px; top:0px;}
50% {background:blue; left:200px; top:200px;}
75% {background:green; left:0px; top:200px;}
100% {background:red; left:0px; top:0px;}
}
</style>
</head>
<body>

<p><b>注释:</b>本例在 Internet Explorer 中无效。</p>

<div></div>

</body>
</html>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: