CSS3 animation

animation

  • 浏览器支持

Internet Explorer 十、Firefox 以及 Opera 支持 animation 属性。java

Safari 和 Chrome 支持替代的 -webkit-animation 属性。web

注释:Internet Explorer 9 以及更早的版本不支持 animation 属性。浏览器

 

  • 定义和用法

  • animation-name       指定要绑定到选择器的关键帧的名称 ,为 @Keyframes建立的动画名

  • animation-duration   用来指定元素播放动画所持续的时间长 

  • animation-timing-function :  设置动画将如何完成一个周期,和transition中的transition-timing-function同样,具备如下六种变换方式

ease:(逐渐变慢)默认值,ease函数等同于贝塞尔曲线(0.25, 0.1, 0.25, 1.0).ide

linear:(匀速),linear 函数等同于贝塞尔曲线(0.0, 0.0, 1.0, 1.0).函数

ease-in:(加速),ease-in 函数等同于贝塞尔曲线(0.42, 0, 1.0, 1.0).动画

ease-out:(减速),ease-out 函数等同于贝塞尔曲线(0, 0, 0.58, 1.0).spa

ease-in-out:(加速而后减速),ease-in-out 函数等同于贝塞尔曲线(0.42, 0, 0.58, 1.0)code

cubic-bezier:特定的cubic-bezier曲线。 (x1, y1, x2, y2)四个值特定于曲线上点P1和点P2。全部值需在[0, 1]区域内,不然无效orm

  • animation-delay   :  设置动画在启动前的延迟间隔。默认0

  • animation-iteration-count   :  是用来指定元素播放动画的循环次数

能够取值<number>为数字,其默认值为 1ip

infinite为无限次数循环

  • animation-direction : normal | alternate 

默认值为normal,若是设置为normal时,动画的每次循环都是向前播放;

alternate,他的做用是,动画播放在第偶数次向前播放,第奇数次向反方向播放。

  • animation-fill-mode : none | forwards | backwards | both

说明:属性规定动画在播放以前或以后,其动画效果是否可见

注释:其属性值是由逗号分隔的一个或多个填充模式关键词

javaScript语法:object.style.animationFillMode=none

参数:

none 不改变默认行为。

forwards 当动画完成后,保持最后一个属性值(在最后一个关键帧中定义)。

backwards 在 animation-delay 所指定的一段时间内,在动画显示以前,应用开始属性值(在第一个关键帧中定义)。

both 向前和向后填充模式都被应用。

  • animation-play-state :running | paused

running为默认值 ,经过running将暂停的动画从新播放

经过paused将正在播放的动画停下了

  

  • 简写

animation: name duration timing-function delay iteration-count direction;
animation: name 2000; ( 省略 timing-function ,delay ,iteration-count ,direction)

 

@keyframes 规则

  要建立CSS3动画,你将不得不了解@keyframes规则。

  @keyframes规则是建立动画。 @keyframes规则内指定一个CSS样式和动画将逐步从目前的样式更改成新的样式。

  

实例:

@keyframes myfirst
{
  from {background: red;}
  to {background: yellow;}
}

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

 

@keyframes myfirst2
{
  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 myfirst2 /* Safari 与 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;}
}

 

把 "myfirst" 动画捆绑到 div 元素,时长:5 秒:

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

div > div { 

  animation: myfirst2 5s;

  -webkit-animation: myfirst2 5s/* Safari 与 Chrome */ 

}

相关文章
相关标签/搜索