torrentkitty暗部,二世寻情,在线弹钢琴
要使用animation动画,先要熟悉一下keyframes,keyframes的语法规则:命名是由”开头,后面紧接着是这个“动画的名称”加上一对花括号“{}”,括号中就是一些不同时间段样式规则。不同关键帧是通过from(相当于0%)、to(相当于100%)或百分比来表示(为了得到最佳的浏览器支持,建议使用百分比),如下定义一个简单的动画:
css code复制内容到剪贴板
- @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;}
- }
-
@keyframes定义好了,要使其能发挥效果,必须通过animation把它绑定到一个选择器,否则动画不会有任何效果。下面列出了animation的属性:
下面设置上述的所有属性
css code复制内容到剪贴板
- animation-name:myfirst;
- animation-duration:5s;
- animation-timing-function:linear;
- animation-delay:1s;
- animation-iteration-count:infinite;
- animation-direction:alternate;
- animation-play-state:running;
-
上述所有代码可以如下简写:
css code复制内容到剪贴板
- animation:myfirst 5s linear 2s infinite alternate;
- animation-play-state:running;
-
浏览器兼容性
internet explorer 10、firefox 以及 opera 支持 @keyframes 规则和 animation 属性。
chrome 和 safari 需要前缀 -webkit-。
注意:internet explorer 9,以及更早的版本,不支持 @keyframe 规则或 animation 属性。
下面给出上面介绍的关于keyframes和animation属性的完整代码示例:
xml/html code复制内容到剪贴板
- <!doctype html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <title>animation演示</title>
- <style>
- div
- {
- width:100px;
- height:100px;
- background:red;
- position:relative;
- animation-name:myfirst;
- animation-duration:5s;
- animation-timing-function:linear;
- animation-delay:1s;
- 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:1s;
- -webkit-animation-iteration-count:infinite;
- -webkit-animation-direction:alternate;
- -webkit-animation-play-state:running;
- }
-
- @keyframes myfirst /*定义动画名*/
- {
- 0% {background:red; left:0px; top:0px;} /*定义起始帧样式,0%相当于from*/
- 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;} /*定义结束帧样式,100%相当于to*/
- }
-
- @-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;}
- }
- </style>
- </head>
- <body>
- <p>该实例在 internet explorer 9 及更早 ie 版本是无效的。</p>
- <div></div>
- </body>
- </html>
上面代码演示了一个正方形沿着一个正方形轨迹运动,基数次按正方向运动,偶数次按反方向运动,运动过程中还带有颜色变化。具体效果,读者可以自行运行代码观察。
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
-
详解CSS3新增的背景属性
CSS3新增属性:background-clip ,background-origin , background-size,本文给大家分享CSS3新增的背景属性...
[阅读全文]
-
-
-
CSS3 旋转立方体问题详解
这篇文章主要介绍了CSS3 旋转立方体问题详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学...
[阅读全文]
-
Grid 宫格常用布局的实现
这篇文章主要介绍了Grid 宫格常用布局的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学...
[阅读全文]
-
-
-
CSS3实现网站商品展示效果图
这篇文章主要介绍了CSS3实现网站商品展示效果图,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习...
[阅读全文]
-
网友评论