CSS3的@keyframes,它可以取代许多网页动画图像,Flash动画,和JAVAScripts。

CSS3的动画属性

下面的表格列出了 @keyframes 规则和所有动画属性:

浏览器支持

表格中的数字表示支持该属性的第一个浏览器版本号。

紧跟在 -webkit-, -ms- 或 -moz- 前的数字为支持该前缀属性的第一个浏览器版本号。

例子:

@keyframes myfirst
{
from {background: red;}
to {background: yellow;}
} @-webkit-keyframes myfirst /* Safari 与 Chrome */
{
from {background: red;}
to {background: yellow;}
}

当在 @keyframes 创建动画,把它绑定到一个选择器,否则动画不会有任何效果。

指定至少这两个CSS3的动画属性绑定向一个选择器:

  • 规定动画的名称
  • 规定动画的时长

如:

div
{
animation: myfirst 5s;
-webkit-animation: myfirst 5s; /* Safari 与 Chrome */
}

注意: 您必须定义动画的名称和动画的持续时间。如果省略的持续时间,动画将无法运行,因为默认值是0。

实例:注意: 该实例在 Internet Explorer 9 及更早 IE 版本是无效的。

div
{
width:100px;
height:100px;
background:red;
position:relative;
animation-name:myfirst;
animation-duration:5s;
animation-timing-function:linear;
animation-delay:2s;
animation-iteration-count:infinite;
animation-direction:alternate;
animation-play-state:running;
/* Safari and Chrome: */
-webkit-animation-name:myfirst;
-webkit-animation-duration:5s;
-webkit-animation-timing-function:linear;
-webkit-animation-delay:2s;
-webkit-animation-iteration-count:infinite;
-webkit-animation-direction:alternate;
-webkit-animation-play-state:running;
} @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;}
} @-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;}
}

最新文章

  1. jquery实现下拉框多选
  2. 学习Maven之Maven Clean Plugin
  3. hibernate-取消关联外键引用数据丢失抛异常的设置@NotFound
  4. 关于python
  5. RunLoop机制理解
  6. fork系统调用(转载)
  7. linux Chrome 安装
  8. input子系统详解
  9. [实变函数]2.2 聚点 (cluster point), 内点 (interior point), 界点 (boundary point)
  10. 转--Android资源总结(环境搭建/ 反编译工具)
  11. SQLiteDatabase中的事务
  12. .NET中反射机制的使用与分析
  13. 鼠标滚轮事件 onmousewheel
  14. SQL数据库的多表查询
  15. mysql 数据库表迁移复制
  16. TCP/IP协议网络编程以及UDP和TCP之传输协议
  17. 006.ks.cfg文件相关
  18. 洛谷P3952 时间复杂度【字符串】【模拟】
  19. vscode 自动提示Threejs
  20. MySQL的事务的处理

热门文章

  1. 使用CSS3实现一个3D相册
  2. 十分钟玩转 jQuery、实例大全
  3. 深入理解 JavaScript,以及 Linux 下的开发调试工具
  4. 【iOS】Xcode8+Swift3 纯代码模式实现 UICollectionView
  5. isEmpty和isNull()区别
  6. ubuntu14 安装及卸载vmware
  7. 我的MYSQL学习心得(五) 运算符
  8. 一步步学习javascript基础篇(7):BOM和DOM
  9. MemCache超详细解读
  10. 安全防范:nginx下git引发的隐私泄露问题