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>
例子:
<!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>
相关文章推荐
- csss3 2D转换
- css3的过渡transition
- 支持IE6以上阴影效果纯CSS
- FLEX BOX (弹性魔盒) 完全指南
- Css
- css3文本效果
- div css float浮动用法(left right)
- CSS 实现图片灰度效果
- 一小时搞定DIV+CSS布局-固定页面开度布局
- CSS3:图片水平垂直居中
- 纯CSS标签tab
- 弹出层遮罩
- 在CSS中设置浮动元素两端对齐的2种方法分享
- CSS 表单元素对齐详解
- 移动设备显示尺寸大全 CSS3媒体查询
- 如何将网格式报表打印成其它样式
- 如何将网格式报表打印成其它样式
- 前端学习笔记—CSS
- Css中为对象应用样式的三种方法:id,class,style
- 浅析CSS负边距